import * as i0 from '@angular/core';
import { Component, Inject, Optional, HostListener, NgModule } from '@angular/core';
import * as i1 from '@awesome-cordova-plugins/barcode-scanner/ngx';
import * as i3 from '@wm/components/base';
import { PROP_STRING, PROP_BOOLEAN, register, StylableComponent, APPLY_STYLES_TYPE, styler, provideAsWidgetRef, WmComponentsModule } from '@wm/components/base';
import { hasCordova } from '@wm/core';
import * as i2 from '@angular/common';
import { CommonModule } from '@angular/common';

const registerProps = () => {
    register('wm-barcodescanner', new Map([
        ['barcodeformat', { value: 'ALL', ...PROP_STRING }],
        ['caption', { value: '', ...PROP_STRING }],
        ['class', PROP_STRING],
        ['iconclass', { value: 'glyphicon glyphicon-barcode', ...PROP_STRING }],
        ['iconsize', { value: '2em', ...PROP_STRING }],
        ['name', PROP_STRING],
        ['show', { value: true, ...PROP_BOOLEAN }],
        ['hint', PROP_STRING],
        ['arialabel', PROP_STRING]
    ]));
};

const _c0 = ["wmBarcodescanner", ""];
const _c1 = a0 => ({ "font-size": a0 });
const DEFAULT_CLS = 'btn app-barcode';
const WIDGET_CONFIG = { widgetType: 'wm-barcodescanner', hostClass: DEFAULT_CLS };
class BarcodeScannerComponent extends StylableComponent {
    static { this.initializeProps = registerProps(); }
    constructor(scanner, inj, explicitContext) {
        super(inj, WIDGET_CONFIG, explicitContext);
        this.scanner = scanner;
        styler(this.nativeElement, this, APPLY_STYLES_TYPE.SCROLLABLE_CONTAINER);
    }
    openBarcodescanner($event) {
        this.scan().then(text => {
            this.datavalue = text;
            this.invokeEventCallback('success', { $event });
        });
    }
    scan() {
        let options = {
            showFlipCameraButton: true,
            showTorchButton: true
        };
        if (hasCordova()) {
            if (this.barcodeformat && this.barcodeformat !== 'ALL') {
                options.formats = this.barcodeformat;
            }
            return this.scanner.scan(options)
                .then(data => data.text);
        }
        return Promise.resolve('BAR_CODE');
    }
    static { this.ɵfac = function BarcodeScannerComponent_Factory(t) { return new (t || BarcodeScannerComponent)(i0.ɵɵdirectiveInject(i1.BarcodeScanner), i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: BarcodeScannerComponent, selectors: [["button", "wmBarcodescanner", ""]], hostBindings: function BarcodeScannerComponent_HostBindings(rf, ctx) { if (rf & 1) {
            i0.ɵɵlistener("click", function BarcodeScannerComponent_click_HostBindingHandler($event) { return ctx.openBarcodescanner($event); });
        } }, exportAs: ["wmBarcodescanner"], features: [i0.ɵɵProvidersFeature([
                provideAsWidgetRef(BarcodeScannerComponent)
            ]), i0.ɵɵInheritDefinitionFeature], attrs: _c0, decls: 2, vars: 5, consts: [[3, "ngClass", "ngStyle"], [1, "btn-caption", 3, "textContent"]], template: function BarcodeScannerComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelement(0, "i", 0)(1, "span", 1);
        } if (rf & 2) {
            i0.ɵɵproperty("ngClass", ctx.iconclass)("ngStyle", i0.ɵɵpureFunction1(3, _c1, ctx.iconsize));
            i0.ɵɵadvance();
            i0.ɵɵproperty("textContent", ctx.caption);
        } }, dependencies: [i2.NgClass, i2.NgStyle, i3.TextContentDirective], encapsulation: 2 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BarcodeScannerComponent, [{
        type: Component,
        args: [{ selector: 'button[wmBarcodescanner]', providers: [
                    provideAsWidgetRef(BarcodeScannerComponent)
                ], exportAs: 'wmBarcodescanner', template: "<i [ngClass]=\"iconclass\" [ngStyle]=\"{'font-size': iconsize}\"></i>\n<span class=\"btn-caption\" [textContent]=\"caption\"></span>" }]
    }], () => [{ type: i1.BarcodeScanner }, { type: i0.Injector }, { type: undefined, decorators: [{
                type: Inject,
                args: ['EXPLICIT_CONTEXT']
            }, {
                type: Optional
            }] }], { openBarcodescanner: [{
            type: HostListener,
            args: ['click', ['$event']]
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(BarcodeScannerComponent, { className: "BarcodeScannerComponent", filePath: "barcode-scanner.component.ts", lineNumber: 21 }); })();

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

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

export { BarcodeScannerComponent, BarcodeScannerModule };
//# sourceMappingURL=index.mjs.map
