"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var jsx_runtime_1 = require("react/jsx-runtime");
var antd_1 = require("antd");
var react_1 = require("react");
var theme_1 = require("@cocalc/util/theme");
function IntegerSlider(_a) {
    var _b, _c;
    var value = _a.value, onChange = _a.onChange, min = _a.min, max = _a.max, maxText = _a.maxText, defaultValue = _a.defaultValue, initialValue = _a.initialValue, units = _a.units, presets = _a.presets, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.step, step = _e === void 0 ? 1 : _e;
    function toNumber(x) {
        return typeof x === "number" ? x : min;
    }
    var _f = __read((0, react_1.useState)((_c = (_b = value !== null && value !== void 0 ? value : initialValue) !== null && _b !== void 0 ? _b : defaultValue) !== null && _c !== void 0 ? _c : min), 2), val = _f[0], setVal = _f[1];
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(antd_1.Row, { children: [(0, jsx_runtime_1.jsx)(antd_1.Col, __assign({ span: 12 }, { children: (0, jsx_runtime_1.jsx)(antd_1.Slider, { disabled: disabled, style: { width: "100%" }, min: min, max: max, onChange: function (x) {
                                onChange(x);
                                setVal(x);
                            }, value: value != null ? toNumber(value) : val, defaultValue: initialValue, step: step }) })), (0, jsx_runtime_1.jsxs)(antd_1.Col, __assign({ span: 12 }, { children: [(0, jsx_runtime_1.jsx)(antd_1.InputNumber, { min: min, max: maxText !== null && maxText !== void 0 ? maxText : max, step: step, disabled: disabled, style: {
                                    marginLeft: "16px",
                                    marginBottom: "5px",
                                    minWidth: "8ex",
                                    width: "20ex",
                                }, defaultValue: initialValue, value: value !== null && value !== void 0 ? value : val, onChange: function (value) {
                                    var val = toNumber(value);
                                    if (step !== 1) {
                                        // quantize val to a multiple of step
                                        val = Math.round(val / step) * step;
                                    }
                                    onChange(val);
                                    setVal(val);
                                }, addonAfter: units }), defaultValue != null && ((0, jsx_runtime_1.jsxs)(antd_1.Button, __assign({ type: "dashed", disabled: disabled || (value !== null && value !== void 0 ? value : val) == defaultValue, style: { marginLeft: "5px" }, onClick: function () {
                                    onChange(defaultValue);
                                    setVal(defaultValue);
                                } }, { children: ["Default: ", defaultValue] })))] }))] }), presets && ((0, jsx_runtime_1.jsx)("div", { children: presets.map(function (number) { return ((0, jsx_runtime_1.jsx)(antd_1.Tag, __assign({ color: disabled ? theme_1.COLORS.GRAY_LL : "blue", style: { cursor: disabled ? "not-allowed" : "pointer" }, onClick: function () {
                        if (disabled)
                            return;
                        onChange(number);
                        setVal(number);
                    } }, { children: number }), number)); }) }))] }));
}
exports.default = IntegerSlider;
//# sourceMappingURL=integer-slider.js.map