import React from "react";
import { LimeElementsWidgetAdapter } from "../adapters";
export class Slider extends React.Component {
    constructor(props) {
        super(props);
        this.props = props;
        this.handleChange = this.handleChange.bind(this);
    }
    render() {
        const props = this.props;
        const schema = props.schema;
        let factor;
        let unit;
        const additionalProps = getAdditionalProps(props.schema);
        if (isPercent(schema)) {
            factor = 100;
            unit = '%';
        }
        return React.createElement(LimeElementsWidgetAdapter, {
            name: 'limel-slider',
            value: props.value,
            events: {
                change: this.handleChange,
            },
            widgetProps: props,
            extraProps: Object.assign({ valuemin: schema.minimum, valuemax: schema.maximum, step: schema.multipleOf, factor: factor, unit: unit }, additionalProps),
        });
    }
    handleChange(event) {
        const props = this.props;
        event.stopPropagation();
        if (!props.onChange) {
            return;
        }
        props.onChange(event.detail);
    }
}
function isPercent(schema) {
    return (schema.multipleOf < 1 && schema.minimum === 0 && schema.maximum === 1);
}
function getAdditionalProps(schema) {
    var _a, _b;
    let props = {};
    if ((_b = (_a = schema.lime) === null || _a === void 0 ? void 0 : _a.component) === null || _b === void 0 ? void 0 : _b.props) {
        props = Object.assign(Object.assign({}, props), schema.lime.component.props);
    }
    return props;
}
