"use strict";

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

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

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

var _Spottable = _interopRequireDefault(require("@enact/spotlight/Spottable"));

var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));

var _compose = _interopRequireDefault(require("ramda/src/compose"));

var _Layout = require("@enact/ui/Layout");

var _Slider = _interopRequireDefault(require("@enact/ui/Slider"));

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

var _Skinnable = _interopRequireDefault(require("../Skinnable"));

var _SliderButtonBehaviorDecorator = _interopRequireDefault(require("./SliderButtonBehaviorDecorator"));

var _SliderButtonModule = _interopRequireDefault(require("./SliderButton.module.css"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": 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; }

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

var SliderKnob = (0, _kind["default"])({
  name: 'SliderKnob',
  propTypes: {
    css: _propTypes["default"].object,
    value: _propTypes["default"].number
  },
  styles: {
    css: _SliderButtonModule["default"],
    className: 'knob'
  },
  computed: {
    style: function style(_ref) {
      var _style = _ref.style,
          value = _ref.value;
      // const factor = Math.abs((value - Math.round(value))) / 4;
      return _objectSpread({
        '--knob-value': value
      }, _style);
    }
  },
  render: function render(_ref2) {
    var rest = Object.assign({}, _ref2);
    delete rest.value; // eslint-disable-next-line enact/prop-types

    delete rest.tooltipComponent;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({}, rest));
  }
});
var SliderProgress = (0, _kind["default"])({
  name: 'SliderProgress',
  propTypes: {
    css: _propTypes["default"].object,
    values: _propTypes["default"].arrayOf(_propTypes["default"].string)
  },
  styles: {
    css: _SliderButtonModule["default"],
    className: 'track'
  },
  render: function render(_ref3) {
    var children = _ref3.children,
        css = _ref3.css,
        values = _ref3.values,
        rest = _objectWithoutProperties(_ref3, ["children", "css", "values"]);

    // eslint-disable-next-line enact/prop-types
    delete rest.progressAnchor; // eslint-disable-next-line enact/prop-types

    delete rest.backgroundProgress;
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Layout.Row, _objectSpread(_objectSpread({}, rest), {}, {
      align: "center",
      children: [children, values ? values.map(function (child) {
        return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
          className: css.client,
          children: child
        }, child);
      }) : null]
    }));
  }
});
/**
 * Renders the base level DOM structure of the component.
 *
 * @class SliderButtonBase
 * @memberof agate/SliderButton
 * @extends ui/Slider.Slider
 * @ui
 * @public
 */

var SliderButtonBase = (0, _kind["default"])({
  name: 'SliderButton',
  propTypes: {
    children: _propTypes["default"].array.isRequired,
    css: _propTypes["default"].object
  },
  styles: {
    css: _SliderButtonModule["default"],
    className: 'sliderButton',
    publicClassNames: true
  },
  computed: {
    max: function max(_ref4) {
      var children = _ref4.children;
      return children && children.length ? children.length - 1 : 0;
    },
    style: function style(_ref5) {
      var children = _ref5.children,
          _style2 = _ref5.style;
      return _objectSpread({
        '--sliderbutton-item-count': children && children.length || 0
      }, _style2);
    }
  },
  render: function render(_ref6) {
    var css = _ref6.css,
        children = _ref6.children,
        max = _ref6.max,
        rest = _objectWithoutProperties(_ref6, ["css", "children", "max"]);

    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Slider["default"], _objectSpread(_objectSpread({}, rest), {}, {
      css: css,
      knobComponent: /*#__PURE__*/(0, _jsxRuntime.jsx)(SliderKnob, {
        css: css
      }),
      progressBarComponent: /*#__PURE__*/(0, _jsxRuntime.jsx)(SliderProgress, {
        values: children
      }),
      step: 1,
      min: 0,
      max: max
    }));
  }
});
/**
 * Agate specific behaviors to apply to [SliderButton]{@link agate/SliderButton.SliderButtonBase}.
 *
 * @hoc
 * @memberof agate/SliderButton
 * @mixes spotlight/Spottable.Spottable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */

exports.SliderButtonBase = SliderButtonBase;
var SliderButtonDecorator = (0, _compose["default"])(_Pure["default"], _SliderButtonBehaviorDecorator["default"], _Spottable["default"], _Skinnable["default"]);
/**
 * Renders a slider that appears as a series of connected buttons.
 *
 * @class SliderButton
 * @memberof agate/SliderButton
 * @extends agate/SliderButton.SliderButtonBase
 * @mixes agate/SliderButton.SliderButtonDecorator
 * @ui
 * @public
 */

exports.SliderButtonDecorator = SliderButtonDecorator;
var SliderButton = SliderButtonDecorator(SliderButtonBase);
exports.SliderButton = SliderButton;
var _default = SliderButton;
exports["default"] = _default;