import * as i0 from '@angular/core';
import { ElementRef, Component, Inject, Optional, ViewChild, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import * as i3 from '@angular/forms';
import { NgModel, NG_VALUE_ACCESSOR, NG_VALIDATORS, FormsModule } from '@angular/forms';
import * as i2 from '@wm/components/base';
import { PROP_STRING, PROP_BOOLEAN, PROP_NUMBER, register, registerFormWidget, provideAs, provideAsWidgetRef, WmComponentsModule } from '@wm/components/base';
import { NumberLocale, InputModule } from '@wm/components/input';
import * as i1 from '@wm/core';
import { FormWidgetType, CURRENCY_INFO } from '@wm/core';

const currencyProps = new Map([
    ['class', PROP_STRING],
    ['currency', PROP_STRING],
    ['datavalue', PROP_STRING],
    ['disabled', PROP_BOOLEAN],
    ['hint', PROP_STRING],
    ['arialabel', PROP_STRING],
    ['maxvalue', PROP_NUMBER],
    ['minvalue', PROP_NUMBER],
    ['name', PROP_STRING],
    ['placeholder', { value: 'Enter value', ...PROP_STRING }],
    ['readonly', PROP_BOOLEAN],
    ['required', PROP_BOOLEAN],
    ['shortcutkey', PROP_STRING],
    ['show', { value: true, ...PROP_BOOLEAN }],
    ['step', { value: 1, ...PROP_NUMBER }],
    ['tabindex', { value: 0, ...PROP_NUMBER }],
    ['trailingzero', { value: false, ...PROP_BOOLEAN }],
    ['inputmode', { value: 'natural', ...PROP_STRING }]
]);
const registerProps = () => {
    register('wm-currency', currencyProps);
    registerFormWidget(FormWidgetType.CURRENCY, new Map(currencyProps));
};

const _c0 = ["input"];
const _c1 = ["wmCurrency", ""];
const DEFAULT_CLS = 'input-group app-currency';
const WIDGET_CONFIG = {
    widgetType: 'wm-currency',
    hostClass: DEFAULT_CLS
};
class CurrencyComponent extends NumberLocale {
    static { this.initializeProps = registerProps(); }
    constructor(inj, appDefaults, i18nService, trailingZeroDecimalPipe, explicitContext) {
        super(inj, WIDGET_CONFIG, i18nService, trailingZeroDecimalPipe, explicitContext);
        this.appDefaults = appDefaults;
        this.currencyCode = this.appDefaults.currencyCode || 'USD';
        this.currencySymbol = CURRENCY_INFO[this.appDefaults.currencyCode || "USD"].symbol;
    }
    onPropertyChange(key, nv, ov) {
        if (key === 'currency') {
            this.currencyCode = nv;
            this.currencySymbol = CURRENCY_INFO[this.currencyCode || this.appDefaults.currencyCode].symbol;
        }
        else {
            super.onPropertyChange(key, nv, ov);
        }
    }
    static { this.ɵfac = function CurrencyComponent_Factory(t) { return new (t || CurrencyComponent)(i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject(i1.AppDefaults), i0.ɵɵdirectiveInject(i1.AbstractI18nService), i0.ɵɵdirectiveInject(i2.TrailingZeroDecimalPipe), i0.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: CurrencyComponent, selectors: [["", "wmCurrency", ""]], viewQuery: function CurrencyComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(NgModel, 7);
            i0.ɵɵviewQuery(_c0, 7, ElementRef);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.ngModel = _t.first);
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.inputEl = _t.first);
        } }, features: [i0.ɵɵProvidersFeature([
                provideAs(CurrencyComponent, NG_VALUE_ACCESSOR, true),
                provideAs(CurrencyComponent, NG_VALIDATORS, true),
                provideAsWidgetRef(CurrencyComponent)
            ]), i0.ɵɵInheritDefinitionFeature], attrs: _c1, decls: 3, vars: 13, consts: [["input", ""], [1, "input-group-addon", 3, "textContent"], ["role", "textbox", "type", "text", "inputmode", "decimal", "focus-target", "", 1, "form-control", "app-textbox", "app-currency-input", 3, "focus", "input", "blur", "ngModelChange", "keydown", "keydown.enter", "keydown.ArrowUp", "keydown.ArrowDown", "autofocus", "readonly", "disabled", "required", "pattern", "ngModel", "ngModelOptions"]], template: function CurrencyComponent_Template(rf, ctx) { if (rf & 1) {
            const _r1 = i0.ɵɵgetCurrentView();
            i0.ɵɵelement(0, "span", 1);
            i0.ɵɵelementStart(1, "input", 2, 0);
            i0.ɵɵlistener("focus", function CurrencyComponent_Template_input_focus_1_listener($event) { i0.ɵɵrestoreView(_r1); return i0.ɵɵresetView(ctx.checkForTrailingZeros($event)); })("input", function CurrencyComponent_Template_input_input_1_listener($event) { i0.ɵɵrestoreView(_r1); return i0.ɵɵresetView(ctx.onInputChange($event.target.value)); })("blur", function CurrencyComponent_Template_input_blur_1_listener($event) { i0.ɵɵrestoreView(_r1); ctx.handleBlur($event); return i0.ɵɵresetView(ctx.checkForTrailingZeros($event)); })("ngModelChange", function CurrencyComponent_Template_input_ngModelChange_1_listener($event) { i0.ɵɵrestoreView(_r1); return i0.ɵɵresetView(ctx.onModelChange($event)); })("keydown", function CurrencyComponent_Template_input_keydown_1_listener($event) { i0.ɵɵrestoreView(_r1); return i0.ɵɵresetView(ctx.validateInputEntry($event)); })("keydown.enter", function CurrencyComponent_Template_input_keydown_enter_1_listener($event) { i0.ɵɵrestoreView(_r1); return i0.ɵɵresetView(ctx.onEnter($event)); })("keydown.ArrowUp", function CurrencyComponent_Template_input_keydown_ArrowUp_1_listener($event) { i0.ɵɵrestoreView(_r1); return i0.ɵɵresetView(ctx.onArrowPress($event, "UP")); })("keydown.ArrowDown", function CurrencyComponent_Template_input_keydown_ArrowDown_1_listener($event) { i0.ɵɵrestoreView(_r1); return i0.ɵɵresetView(ctx.onArrowPress($event, "DOWN")); });
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵproperty("textContent", ctx.currencySymbol);
            i0.ɵɵadvance();
            i0.ɵɵproperty("autofocus", ctx.autofocus)("readonly", ctx.readonly)("disabled", ctx.disabled)("required", ctx.required)("pattern", ctx.regexp)("ngModel", ctx.displayValue)("ngModelOptions", ctx.ngModelOptions);
            i0.ɵɵattribute("name", ctx.name)("aria-label", ctx.arialabel || ctx.currencyCode)("tabindex", ctx.tabindex)("placeholder", ctx.placeholder)("accesskey", ctx.shortcutkey);
        } }, dependencies: [i3.DefaultValueAccessor, i3.NgControlStatus, i3.RequiredValidator, i3.PatternValidator, i3.NgModel, i2.TextContentDirective], encapsulation: 2 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CurrencyComponent, [{
        type: Component,
        args: [{ selector: '[wmCurrency]', providers: [
                    provideAs(CurrencyComponent, NG_VALUE_ACCESSOR, true),
                    provideAs(CurrencyComponent, NG_VALIDATORS, true),
                    provideAsWidgetRef(CurrencyComponent)
                ], template: "<span class=\"input-group-addon\" [textContent]=\"currencySymbol\"></span>\n<input class=\"form-control app-textbox app-currency-input\"\n       #input\n       role=\"textbox\"\n       type=\"text\"\n       inputmode=\"decimal\"\n       focus-target\n       [autofocus]=\"autofocus\"\n       [readonly]=\"readonly\"\n       [disabled]=\"disabled\"\n       [required]=\"required\"\n       [pattern]=\"regexp\"\n       [attr.name]=\"name\"\n       [attr.aria-label]=\"arialabel || currencyCode\"\n       [attr.tabindex]=\"tabindex\"\n       [attr.placeholder]=\"placeholder\"\n       [attr.accesskey]=\"shortcutkey\"\n       [ngModel]=\"displayValue\"\n       [ngModelOptions]=\"ngModelOptions\"\n\n       (focus)=\"checkForTrailingZeros($event)\"\n       (input)=\"onInputChange($event.target.value)\"\n       (blur)=\"handleBlur($event); checkForTrailingZeros($event);\"\n       (ngModelChange)=\"onModelChange($event)\"\n       (keydown)=\"validateInputEntry($event);\"\n       (keydown.enter)=\"onEnter($event)\"\n       (keydown.ArrowUp)=\"onArrowPress($event, 'UP')\"\n       (keydown.ArrowDown)=\"onArrowPress($event, 'DOWN')\">\n" }]
    }], () => [{ type: i0.Injector }, { type: i1.AppDefaults }, { type: i1.AbstractI18nService }, { type: i2.TrailingZeroDecimalPipe }, { type: undefined, decorators: [{
                type: Inject,
                args: ['EXPLICIT_CONTEXT']
            }, {
                type: Optional
            }] }], { ngModel: [{
            type: ViewChild,
            args: [NgModel, { static: true }]
        }], inputEl: [{
            type: ViewChild,
            args: ['input', { static: true, read: ElementRef }]
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(CurrencyComponent, { className: "CurrencyComponent", filePath: "currency.component.ts", lineNumber: 26 }); })();

const components = [
    CurrencyComponent
];
class CurrencyModule {
    static { this.ɵfac = function CurrencyModule_Factory(t) { return new (t || CurrencyModule)(); }; }
    static { this.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: CurrencyModule }); }
    static { this.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule,
            FormsModule,
            InputModule,
            WmComponentsModule] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CurrencyModule, [{
        type: NgModule,
        args: [{
                imports: [
                    CommonModule,
                    FormsModule,
                    InputModule,
                    WmComponentsModule
                ],
                declarations: [...components],
                exports: [...components]
            }]
    }], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(CurrencyModule, { declarations: [CurrencyComponent], imports: [CommonModule,
        FormsModule,
        InputModule,
        WmComponentsModule], exports: [CurrencyComponent] }); })();

/**
 * Generated bundle index. Do not edit.
 */

export { CurrencyComponent, CurrencyModule };
//# sourceMappingURL=index.mjs.map
