import { DOCUMENT, NgIf } from '@angular/common';
import { ChangeDetectionStrategy, Component, computed, inject, Input, signal, ViewEncapsulation, } from '@angular/core';
import { tuiInjectElement } from '@taiga-ui/cdk/utils/dom';
import { tuiClamp, tuiSum } from '@taiga-ui/cdk/utils/math';
import { TuiButton } from '@taiga-ui/core/components/button';
import { TUI_TEXTFIELD_OPTIONS, TuiTextfieldContent, } from '@taiga-ui/core/components/textfield';
import { TuiInputNumberDirective } from '../input-number.directive';
import { TUI_INPUT_NUMBER_OPTIONS, } from '../input-number.options';
import { TuiInputNumberStepService } from './input-number-step.service';
import * as i0 from "@angular/core";
class TuiInputNumberStep {
    constructor() {
        this.el = tuiInjectElement();
        this.hold = inject(TuiInputNumberStepService);
        this.$ = this.hold.steps$.subscribe((value) => this.onStep(value));
        this.appearance = inject(TUI_TEXTFIELD_OPTIONS).appearance;
        this.options = inject(TUI_INPUT_NUMBER_OPTIONS);
        this.input = inject(TuiInputNumberDirective, { self: true });
        this.step = signal(this.options.step);
        this.value = computed(() => this.input.value() ?? NaN);
        this.doc = inject(DOCUMENT);
    }
    // TODO(v5): replace with signal input
    set stepSetter(x) {
        this.step.set(x);
    }
    onStep(step) {
        const current = this.input.value() ?? 0;
        const value = tuiSum(current, step);
        this.input.setValue(tuiClamp(value, this.input.min(), this.input.max()));
        this.el.setSelectionRange(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiInputNumberStep, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: TuiInputNumberStep, isStandalone: true, selector: "input[tuiInputNumber][step]", inputs: { stepSetter: ["step", "stepSetter"] }, host: { attributes: { "ngSkipHydration": "true" }, listeners: { "keydown.arrowDown.prevent": "onStep(-step())", "keydown.arrowUp.prevent": "onStep(step())" }, properties: { "class._with-buttons": "step()" } }, providers: [TuiInputNumberStepService], ngImport: i0, template: "<ng-container *tuiTextfieldContent>\n    <section\n        *ngIf=\"step()\"\n        class=\"t-input-number-buttons\"\n    >\n        <button\n            size=\"s\"\n            tabindex=\"-1\"\n            tuiIconButton\n            type=\"button\"\n            class=\"t-button\"\n            [appearance]=\"appearance()\"\n            [disabled]=\"!input.interactive() || value() >= input.max()\"\n            [iconStart]=\"options.icons.increase\"\n            (click.prevent)=\"onStep(step())\"\n            (pointerdown.prevent)=\"hold.next(step())\"\n        >\n            +\n        </button>\n\n        <button\n            size=\"s\"\n            tabindex=\"-1\"\n            tuiIconButton\n            type=\"button\"\n            class=\"t-button\"\n            [appearance]=\"appearance()\"\n            [disabled]=\"!input.interactive() || value() <= input.min()\"\n            [iconStart]=\"options.icons.decrease\"\n            (click.prevent)=\"onStep(-step())\"\n            (pointerdown.prevent)=\"hold.next(-step())\"\n        >\n            -\n        </button>\n    </section>\n</ng-container>\n", styles: [".t-input-number-buttons.t-input-number-buttons{position:absolute;right:0;display:flex;block-size:var(--t-height);flex-direction:column;gap:.125rem;border-radius:inherit}@supports (inset-inline-end: 0){.t-input-number-buttons.t-input-number-buttons{right:unset;inset-inline-end:0}}tui-textfield[data-size=s] .t-input-number-buttons.t-input-number-buttons{flex-direction:row-reverse}.t-input-number-buttons.t-input-number-buttons>*{flex:1 1 0;border-radius:0}.t-input-number-buttons.t-input-number-buttons>*:first-child{border-top-right-radius:inherit}.t-input-number-buttons.t-input-number-buttons>*:last-child{border-bottom-right-radius:inherit}[dir=rtl] .t-input-number-buttons.t-input-number-buttons>*:first-child{border-radius:0;border-top-left-radius:inherit}[dir=rtl] .t-input-number-buttons.t-input-number-buttons>*:last-child{border-radius:0;border-bottom-left-radius:inherit}tui-textfield[data-size=l] .t-input-number-buttons.t-input-number-buttons>*{inline-size:var(--tui-height-m)}tui-textfield[data-size=s] .t-input-number-buttons.t-input-number-buttons>*:first-child{border-top-right-radius:inherit;border-bottom-right-radius:inherit}tui-textfield[data-size=s] .t-input-number-buttons.t-input-number-buttons>*:last-child{border-radius:0}[tuiInputNumber]._with-buttons{border-top-right-radius:0;border-bottom-right-radius:0}[dir=rtl] [tuiInputNumber]._with-buttons{border-radius:inherit;border-top-left-radius:0;border-bottom-left-radius:0}tui-textfield[data-size=l]{--t-input-number-offset-end: calc(var(--tui-height-m) + .125rem)}tui-textfield[data-size=m]{--t-input-number-offset-end: calc(var(--tui-height-s) + .125rem)}tui-textfield[data-size=s]{--t-input-number-offset-end: calc(2 * var(--tui-height-s) + .25rem)}[tuiInputNumber]._with-buttons,[tuiInputNumber]._with-buttons~.t-template{inline-size:calc(100% - var(--t-input-number-offset-end));margin-inline-end:var(--t-input-number-offset-end)}[tuiInputNumber]._with-buttons~.t-content{margin-inline-end:var(--t-input-number-offset-end)}\n"], dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: TuiButton, selector: "a[tuiButton],button[tuiButton],a[tuiIconButton],button[tuiIconButton]", inputs: ["size"] }, { kind: "directive", type: TuiTextfieldContent, selector: "ng-template[tuiTextfieldContent]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
export { TuiInputNumberStep };
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiInputNumberStep, decorators: [{
            type: Component,
            args: [{ standalone: true, selector: 'input[tuiInputNumber][step]', imports: [NgIf, TuiButton, TuiTextfieldContent], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, providers: [TuiInputNumberStepService], host: {
                        ngSkipHydration: 'true',
                        '(keydown.arrowDown.prevent)': 'onStep(-step())',
                        '(keydown.arrowUp.prevent)': 'onStep(step())',
                        '[class._with-buttons]': 'step()',
                    }, template: "<ng-container *tuiTextfieldContent>\n    <section\n        *ngIf=\"step()\"\n        class=\"t-input-number-buttons\"\n    >\n        <button\n            size=\"s\"\n            tabindex=\"-1\"\n            tuiIconButton\n            type=\"button\"\n            class=\"t-button\"\n            [appearance]=\"appearance()\"\n            [disabled]=\"!input.interactive() || value() >= input.max()\"\n            [iconStart]=\"options.icons.increase\"\n            (click.prevent)=\"onStep(step())\"\n            (pointerdown.prevent)=\"hold.next(step())\"\n        >\n            +\n        </button>\n\n        <button\n            size=\"s\"\n            tabindex=\"-1\"\n            tuiIconButton\n            type=\"button\"\n            class=\"t-button\"\n            [appearance]=\"appearance()\"\n            [disabled]=\"!input.interactive() || value() <= input.min()\"\n            [iconStart]=\"options.icons.decrease\"\n            (click.prevent)=\"onStep(-step())\"\n            (pointerdown.prevent)=\"hold.next(-step())\"\n        >\n            -\n        </button>\n    </section>\n</ng-container>\n", styles: [".t-input-number-buttons.t-input-number-buttons{position:absolute;right:0;display:flex;block-size:var(--t-height);flex-direction:column;gap:.125rem;border-radius:inherit}@supports (inset-inline-end: 0){.t-input-number-buttons.t-input-number-buttons{right:unset;inset-inline-end:0}}tui-textfield[data-size=s] .t-input-number-buttons.t-input-number-buttons{flex-direction:row-reverse}.t-input-number-buttons.t-input-number-buttons>*{flex:1 1 0;border-radius:0}.t-input-number-buttons.t-input-number-buttons>*:first-child{border-top-right-radius:inherit}.t-input-number-buttons.t-input-number-buttons>*:last-child{border-bottom-right-radius:inherit}[dir=rtl] .t-input-number-buttons.t-input-number-buttons>*:first-child{border-radius:0;border-top-left-radius:inherit}[dir=rtl] .t-input-number-buttons.t-input-number-buttons>*:last-child{border-radius:0;border-bottom-left-radius:inherit}tui-textfield[data-size=l] .t-input-number-buttons.t-input-number-buttons>*{inline-size:var(--tui-height-m)}tui-textfield[data-size=s] .t-input-number-buttons.t-input-number-buttons>*:first-child{border-top-right-radius:inherit;border-bottom-right-radius:inherit}tui-textfield[data-size=s] .t-input-number-buttons.t-input-number-buttons>*:last-child{border-radius:0}[tuiInputNumber]._with-buttons{border-top-right-radius:0;border-bottom-right-radius:0}[dir=rtl] [tuiInputNumber]._with-buttons{border-radius:inherit;border-top-left-radius:0;border-bottom-left-radius:0}tui-textfield[data-size=l]{--t-input-number-offset-end: calc(var(--tui-height-m) + .125rem)}tui-textfield[data-size=m]{--t-input-number-offset-end: calc(var(--tui-height-s) + .125rem)}tui-textfield[data-size=s]{--t-input-number-offset-end: calc(2 * var(--tui-height-s) + .25rem)}[tuiInputNumber]._with-buttons,[tuiInputNumber]._with-buttons~.t-template{inline-size:calc(100% - var(--t-input-number-offset-end));margin-inline-end:var(--t-input-number-offset-end)}[tuiInputNumber]._with-buttons~.t-content{margin-inline-end:var(--t-input-number-offset-end)}\n"] }]
        }], propDecorators: { stepSetter: [{
                type: Input,
                args: ['step']
            }] } });
//# sourceMappingURL=data:application/json;base64, 