var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
import { jsx } from "react/jsx-runtime";
import React from "react";
import { bool, string, number, arrayOf, shape, oneOfType } from "prop-types";
import styled, { withTheme } from "styled-components";
import RCSlider from "rc-slider/lib/Slider";
import RCRange from "rc-slider/lib/Range";
import Marker from "./Marker";
const StyledSlider = styled(RCSlider)`
  position: relative;
  width: 100%;

  ${({ marks }) => `
    padding-bottom: ${marks ? 40 : 15}px;
  `}

  * {
    box-sizing: border-box;
  }
`;
const StyledRange = styled(RCRange)`
  position: relative;
  width: 100%;

  ${({ marks }) => `
    padding-bottom: ${marks ? 40 : 15}px;
  `}

  * {
    box-sizing: border-box;
  }
`;
const emptyArr = [];
const defaultValues = [0];
const Slider = (_a) => {
  var _b = _a, {
    snapped = false,
    tooltip = emptyArr,
    values = defaultValues,
    max = 10,
    maxLabel,
    min = 0,
    minLabel,
    theme: {
      yoga: {
        components: { slider }
      }
    }
  } = _b, props = __objRest(_b, [
    "snapped",
    "tooltip",
    "values",
    "max",
    "maxLabel",
    "min",
    "minLabel",
    "theme"
  ]);
  const styles = {
    commonTrackStyle: {
      borderRadius: slider.track.border.radius,
      height: 4,
      position: "absolute",
      width: "100%"
    },
    trackStyle: {
      backgroundColor: slider.track.backgroundColor.active
    },
    railStyle: {
      backgroundColor: slider.track.backgroundColor.inactive
    },
    commonStepStyle: {
      borderRadius: slider.step.border.radius,
      marginLeft: -4,
      position: "absolute",
      height: 10,
      top: -3,
      width: 10
    },
    activeStepStyle: {
      backgroundColor: slider.track.backgroundColor.active
    },
    inactiveStepStyle: {
      backgroundColor: slider.track.backgroundColor.inactive
    },
    labelStyle: {
      position: "absolute",
      top: 15
    }
  };
  return values.length > 1 ? /* @__PURE__ */ jsx(
    StyledRange,
    __spreadProps(__spreadValues({}, props), {
      dots: snapped,
      value: values,
      allowCross: false,
      marks: {
        [min]: {
          label: minLabel,
          style: __spreadProps(__spreadValues({}, styles.labelStyle), { transform: "translateX(0%)" })
        },
        [max]: {
          label: maxLabel,
          style: __spreadProps(__spreadValues({}, styles.labelStyle), { transform: "translateX(-100%)" })
        }
      },
      trackStyle: [
        __spreadValues(__spreadValues({}, styles.commonTrackStyle), styles.trackStyle)
      ],
      railStyle: __spreadValues(__spreadValues({}, styles.commonTrackStyle), styles.railStyle),
      dotStyle: snapped ? __spreadValues(__spreadValues({}, styles.commonStepStyle), styles.inactiveStepStyle) : void 0,
      activeDotStyle: snapped ? __spreadValues(__spreadValues({}, styles.commonStepStyle), styles.activeStepStyle) : void 0,
      max,
      min,
      handle: (_a2) => {
        var _b2 = _a2, { ref, index } = _b2, rest = __objRest(_b2, ["ref", "index"]);
        return /* @__PURE__ */ jsx(
          Marker,
          __spreadValues({
            values,
            tooltip,
            index
          }, rest),
          index
        );
      }
    })
  ) : /* @__PURE__ */ jsx(
    StyledSlider,
    __spreadProps(__spreadValues({}, props), {
      prefixCls: "yoga",
      dots: snapped,
      value: values[0],
      marks: {
        [min]: {
          label: minLabel,
          style: __spreadProps(__spreadValues({}, styles.labelStyle), { transform: "translateX(0%)" })
        },
        [max]: {
          label: maxLabel,
          style: __spreadProps(__spreadValues({}, styles.labelStyle), { transform: "translateX(-100%)" })
        }
      },
      trackStyle: __spreadValues(__spreadValues({}, styles.commonTrackStyle), styles.trackStyle),
      railStyle: __spreadValues(__spreadValues({}, styles.commonTrackStyle), styles.railStyle),
      dotStyle: snapped ? __spreadValues(__spreadValues({}, styles.commonStepStyle), styles.inactiveStepStyle) : void 0,
      activeDotStyle: snapped ? __spreadValues(__spreadValues({}, styles.commonStepStyle), styles.activeStepStyle) : void 0,
      max,
      min,
      handle: (_c) => {
        var _d = _c, { ref, index } = _d, rest = __objRest(_d, ["ref", "index"]);
        return /* @__PURE__ */ jsx(
          Marker,
          __spreadValues({
            values,
            tooltip,
            index
          }, rest),
          index
        );
      }
    })
  );
};
Slider.propTypes = {
  /** set the max value */
  max: number,
  /** label to be displayed at max value */
  maxLabel: oneOfType([string, number]),
  /** set the min value */
  min: number,
  /** label to be displayed at min value */
  minLabel: oneOfType([string, number]),
  /** make slider be snap through dots */
  snapped: bool,
  /** accepts a shape with 'ribbon', 'title', 'description', 'visible' and 'step' properties */
  tooltip: arrayOf(
    shape({
      ribbon: string,
      title: string,
      description: string,
      visible: bool,
      step: number
    })
  ),
  /** an array that accepts one or two numbers, this determines how many markers will be displayed */
  values: arrayOf(number)
};
Slider.displayName = "Slider";
var Slider_default = withTheme(Slider);
export {
  Slider_default as default
};
