import { h } from "@stencil/core";
/**
 * InputNumber 数字输入框组件
 * 仅允许输入标准的数字值，可定义范围
 */
export class InputNumber {
    /**
     * 绑定值
     */
    modelValue = 0;
    /**
     * 计数器尺寸
     */
    size = 'default';
    /**
     * 是否禁用
     * @default false
     */
    disabled = false;
    /**
     * 是否只读
     * @default false
     */
    readonly = false;
    /**
     * 最小值
     * @default -Infinity
     */
    min = -Infinity;
    /**
     * 最大值
     * @default Infinity
     */
    max = Infinity;
    /**
     * 计数器步长
     * @default 1
     */
    step = 1;
    /**
     * 精度
     */
    precision;
    /**
     * 是否只能输入 step 的倍数
     * @default false
     */
    stepStrictly = false;
    /**
     * 是否使用控制按钮
     * @default true
     */
    controls = true;
    /**
     * 控制按钮位置
     */
    controlsPosition = '';
    /**
     * 原生 name 属性
     */
    name;
    /**
     * 原生 id 属性
     */
    inputId;
    /**
     * 原生 placeholder 属性
     */
    placeholder;
    currentValue = 0;
    /**
     * 值改变事件
     */
    hbChange;
    /**
     * 输入事件
     */
    hbInput;
    componentDidLoad() {
        this.currentValue = this.modelValue;
    }
    /** 受控模式：外部修改 modelValue 时同步内部 currentValue，保证 UI 与值一致 */
    handleModelValueChange() {
        this.currentValue = this.modelValue;
    }
    formatValue(value) {
        if (this.precision !== undefined) {
            return Number(value.toFixed(this.precision));
        }
        return value;
    }
    clampValue(value) {
        let clamped = Math.max(this.min, Math.min(this.max, value));
        if (this.stepStrictly) {
            const step = this.step;
            clamped = Math.round(clamped / step) * step;
        }
        return this.formatValue(clamped);
    }
    handleInput = (e) => {
        const target = e.target;
        const value = parseFloat(target.value);
        if (isNaN(value)) {
            this.currentValue = this.min;
        }
        else {
            this.currentValue = this.clampValue(value);
        }
        this.modelValue = this.currentValue;
        this.hbInput.emit(this.currentValue);
    };
    handleChange = () => {
        this.hbChange.emit(this.currentValue);
    };
    increase = () => {
        if (this.disabled || this.readonly)
            return;
        const newValue = this.clampValue(this.currentValue + this.step);
        this.currentValue = newValue;
        this.modelValue = newValue;
        this.hbChange.emit(newValue);
    };
    decrease = () => {
        if (this.disabled || this.readonly)
            return;
        const newValue = this.clampValue(this.currentValue - this.step);
        this.currentValue = newValue;
        this.modelValue = newValue;
        this.hbChange.emit(newValue);
    };
    render() {
        return (h("div", { key: '490fe763a00f34486cbbe6502204433071a863eb', class: {
                'hb-input-number': true,
                [`hb-input-number--${this.size}`]: true,
                'hb-input-number--disabled': this.disabled,
                'hb-input-number--controls-right': this.controlsPosition === 'right',
                'hb-input-number--without-controls': !this.controls,
            } }, this.controls && this.controlsPosition !== 'right' && (h("span", { key: 'a43a038a8914dbff0c8b9759c04c74fa791f2e6c', class: {
                'hb-input-number__decrease': true,
                'hb-input-number__decrease--disabled': this.currentValue <= this.min,
            }, onClick: this.decrease }, "\u2212")), h("input", { key: '83a7bb1d73a709e92f31044396fdb73daed77ea9', type: "number", id: this.inputId, name: this.name, class: "hb-input-number__inner", value: this.currentValue, disabled: this.disabled, readonly: this.readonly, placeholder: this.placeholder, min: this.min, max: this.max, step: this.step, onInput: this.handleInput, onChange: this.handleChange }), this.controls && this.controlsPosition === 'right' && (h("span", { key: 'e202c7b06c991550eb9a5cae441ead7d82231b0f', class: "hb-input-number__controls" }, h("span", { key: '876db137bb4539e93a1f7ccb08a2fb754722a7bf', class: {
                'hb-input-number__increase': true,
                'hb-input-number__increase--disabled': this.currentValue >= this.max,
            }, onClick: this.increase }, "+"), h("span", { key: '98acd918f10a7f8d3c399aa60677eac231be503b', class: {
                'hb-input-number__decrease': true,
                'hb-input-number__decrease--disabled': this.currentValue <= this.min,
            }, onClick: this.decrease }, "\u2212"))), this.controls && this.controlsPosition !== 'right' && (h("span", { key: '4befdfc2a0d7ac3af63027f0947f27d866fbe158', class: {
                'hb-input-number__increase': true,
                'hb-input-number__increase--disabled': this.currentValue >= this.max,
            }, onClick: this.increase }, "+"))));
    }
    static get is() { return "hb-input-number"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["input-number.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["input-number.css"]
        };
    }
    static get properties() {
        return {
            "modelValue": {
                "type": "number",
                "mutable": true,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u7ED1\u5B9A\u503C"
                },
                "getter": false,
                "setter": false,
                "attribute": "model-value",
                "reflect": false,
                "defaultValue": "0"
            },
            "size": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "'large' | 'default' | 'small'",
                    "resolved": "\"default\" | \"large\" | \"small\"",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u8BA1\u6570\u5668\u5C3A\u5BF8"
                },
                "getter": false,
                "setter": false,
                "attribute": "size",
                "reflect": false,
                "defaultValue": "'default'"
            },
            "disabled": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "false"
                        }],
                    "text": "\u662F\u5426\u7981\u7528"
                },
                "getter": false,
                "setter": false,
                "attribute": "disabled",
                "reflect": false,
                "defaultValue": "false"
            },
            "readonly": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "false"
                        }],
                    "text": "\u662F\u5426\u53EA\u8BFB"
                },
                "getter": false,
                "setter": false,
                "attribute": "readonly",
                "reflect": false,
                "defaultValue": "false"
            },
            "min": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "-Infinity"
                        }],
                    "text": "\u6700\u5C0F\u503C"
                },
                "getter": false,
                "setter": false,
                "attribute": "min",
                "reflect": false,
                "defaultValue": "-Infinity"
            },
            "max": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "Infinity"
                        }],
                    "text": "\u6700\u5927\u503C"
                },
                "getter": false,
                "setter": false,
                "attribute": "max",
                "reflect": false,
                "defaultValue": "Infinity"
            },
            "step": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "1"
                        }],
                    "text": "\u8BA1\u6570\u5668\u6B65\u957F"
                },
                "getter": false,
                "setter": false,
                "attribute": "step",
                "reflect": false,
                "defaultValue": "1"
            },
            "precision": {
                "type": "number",
                "mutable": false,
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "\u7CBE\u5EA6"
                },
                "getter": false,
                "setter": false,
                "attribute": "precision",
                "reflect": false
            },
            "stepStrictly": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "false"
                        }],
                    "text": "\u662F\u5426\u53EA\u80FD\u8F93\u5165 step \u7684\u500D\u6570"
                },
                "getter": false,
                "setter": false,
                "attribute": "step-strictly",
                "reflect": false,
                "defaultValue": "false"
            },
            "controls": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [{
                            "name": "default",
                            "text": "true"
                        }],
                    "text": "\u662F\u5426\u4F7F\u7528\u63A7\u5236\u6309\u94AE"
                },
                "getter": false,
                "setter": false,
                "attribute": "controls",
                "reflect": false,
                "defaultValue": "true"
            },
            "controlsPosition": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "'' | 'right'",
                    "resolved": "\"\" | \"right\"",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "\u63A7\u5236\u6309\u94AE\u4F4D\u7F6E"
                },
                "getter": false,
                "setter": false,
                "attribute": "controls-position",
                "reflect": false,
                "defaultValue": "''"
            },
            "name": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "\u539F\u751F name \u5C5E\u6027"
                },
                "getter": false,
                "setter": false,
                "attribute": "name",
                "reflect": false
            },
            "inputId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "\u539F\u751F id \u5C5E\u6027"
                },
                "getter": false,
                "setter": false,
                "attribute": "input-id",
                "reflect": false
            },
            "placeholder": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "\u539F\u751F placeholder \u5C5E\u6027"
                },
                "getter": false,
                "setter": false,
                "attribute": "placeholder",
                "reflect": false
            }
        };
    }
    static get states() {
        return {
            "currentValue": {}
        };
    }
    static get events() {
        return [{
                "method": "hbChange",
                "name": "hbChange",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "\u503C\u6539\u53D8\u4E8B\u4EF6"
                },
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                }
            }, {
                "method": "hbInput",
                "name": "hbInput",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "\u8F93\u5165\u4E8B\u4EF6"
                },
                "complexType": {
                    "original": "number",
                    "resolved": "number",
                    "references": {}
                }
            }];
    }
    static get watchers() {
        return [{
                "propName": "modelValue",
                "methodName": "handleModelValueChange"
            }];
    }
}
//# sourceMappingURL=InputNumber.js.map
