var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { MelodicComponent } from '@melodicdev/core';
import { sliderTemplate } from './slider.template.js';
import { sliderStyles } from './slider.styles.js';
/**
 * ml-slider - Range slider input
 *
 * @example
 * ```html
 * <ml-slider label="Volume" value="50"></ml-slider>
 * <ml-slider label="Price" min="0" max="1000" step="10" show-value></ml-slider>
 * ```
 *
 * @fires ml:input - Emitted on each input change
 * @fires ml:change - Emitted on final change (mouseup/touchend)
 */
let SliderComponent = class SliderComponent {
    constructor() {
        /** Label text */
        this.label = '';
        /** Current value */
        this.value = 50;
        /** Minimum value */
        this.min = 0;
        /** Maximum value */
        this.max = 100;
        /** Step increment */
        this.step = 1;
        /** Slider size */
        this.size = 'md';
        /** Disable the slider */
        this.disabled = false;
        /** Show current value */
        this.showValue = false;
        /** Hint text */
        this.hint = '';
        /** Error message */
        this.error = '';
        this.handleInput = (event) => {
            const target = event.target;
            this.value = Number(target.value);
            this.elementRef.dispatchEvent(new CustomEvent('ml:input', {
                bubbles: true,
                composed: true,
                detail: { value: this.value }
            }));
        };
        this.handleChange = (event) => {
            const target = event.target;
            this.value = Number(target.value);
            this.elementRef.dispatchEvent(new CustomEvent('ml:change', {
                bubbles: true,
                composed: true,
                detail: { value: this.value }
            }));
        };
    }
    /** Ratio 0–1 for fill track */
    get ratio() {
        const range = this.max - this.min;
        if (range <= 0)
            return 0;
        return (this.value - this.min) / range;
    }
    /** CSS width for fill that matches native thumb position */
    get fillWidth() {
        const p = this.ratio;
        return `calc(${p * 100}% + ${10 - p * 20}px)`;
    }
};
SliderComponent = __decorate([
    MelodicComponent({
        selector: 'ml-slider',
        template: sliderTemplate,
        styles: sliderStyles,
        attributes: ['label', 'value', 'min', 'max', 'step', 'size', 'disabled', 'show-value', 'hint', 'error']
    })
], SliderComponent);
export { SliderComponent };
