import { __assign } from '../../node_modules/tslib/tslib.es6.js';
import React from 'react';
import { Slider, SliderMark, Box, SliderTrack, SliderFilledTrack, SliderThumb } from '@chakra-ui/react';

var emptyItemOffset = 0;
var firstItemOffset = 1;
var getItemOffset = function (applyIndentation) {
    return applyIndentation ? firstItemOffset : emptyItemOffset;
};
var getSliderStepValue = function (marks, applyIndentation, value) {
    var selectedMarkIndex = marks.findIndex(function (mark) { return mark.value === value; });
    if (selectedMarkIndex < emptyItemOffset) {
        return getItemOffset(applyIndentation);
    }
    return selectedMarkIndex + getItemOffset(applyIndentation);
};
var getSliderMarks = function (marks, applyIndentation) {
    return marks.map(function (mark, index) { return (__assign(__assign({}, mark), { stepValue: index + getItemOffset(applyIndentation) })); });
};
var DiscreteSlider = function (_a) {
    var marks = _a.marks, _b = _a.applyIndentation, applyIndentation = _b === void 0 ? true : _b, onValueChanged = _a.onValueChanged, value = _a.value;
    var sliderStepValue = getSliderStepValue(marks, applyIndentation, value);
    var sliderMarks = getSliderMarks(marks, applyIndentation);
    var handleOnChange = function (newStepValue) {
        var _a;
        if (applyIndentation && newStepValue < firstItemOffset)
            return;
        var newSliderMark = (_a = sliderMarks.find(function (mark) { return mark.stepValue === newStepValue; })) === null || _a === void 0 ? void 0 : _a.value;
        onValueChanged(newSliderMark);
    };
    return (React.createElement(Slider, { step: 1, max: sliderMarks.length - 1 + getItemOffset(applyIndentation), value: sliderStepValue, onChange: handleOnChange, focusThumbOnChange: false }, sliderMarks === null || sliderMarks === void 0 ? void 0 :
        sliderMarks.map(function (_a, index) {
            var stepValue = _a.stepValue, label = _a.label;
            return (React.createElement(SliderMark, { key: index, value: stepValue, fontWeight: sliderStepValue === stepValue ? 'bold' : 'normal' },
                React.createElement(Box, { style: { pointerEvents: 'all' } }, label)));
        }),
        React.createElement(SliderTrack, null,
            React.createElement(SliderFilledTrack, null)),
        React.createElement(SliderThumb, null)));
};

export { DiscreteSlider as default };
//# sourceMappingURL=index.js.map
