(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@awesome-cordova-plugins/camera/ngx'), require('@awesome-cordova-plugins/media-capture/ngx'), require('@wm/components/base'), require('@wm/core'), require('@angular/common')) :
    typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@awesome-cordova-plugins/camera/ngx', '@awesome-cordova-plugins/media-capture/ngx', '@wm/components/base', '@wm/core', '@angular/common'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.wm = global.wm || {}, global.wm.mobile = global.wm.mobile || {}, global.wm.mobile.components = global.wm.mobile.components || {}, global.wm.mobile.components.device = global.wm.mobile.components.device || {}, global.wm.mobile.components.device.camera = {}), global.ng.core, global.awesomeCordova.plugins, global.awesomeCordova.plugins, global.wm.components.base, global.wm.core, global.ng.common));
})(this, (function (exports, i0, i1, i2, base, core, i3) { 'use strict';

    function _interopNamespaceDefault(e) {
        var n = Object.create(null);
        if (e) {
            Object.keys(e).forEach(function (k) {
                if (k !== 'default') {
                    var d = Object.getOwnPropertyDescriptor(e, k);
                    Object.defineProperty(n, k, d.get ? d : {
                        enumerable: true,
                        get: function () { return e[k]; }
                    });
                }
            });
        }
        n.default = e;
        return Object.freeze(n);
    }

    var i0__namespace = /*#__PURE__*/_interopNamespaceDefault(i0);
    var i1__namespace = /*#__PURE__*/_interopNamespaceDefault(i1);
    var i2__namespace = /*#__PURE__*/_interopNamespaceDefault(i2);
    var i3__namespace = /*#__PURE__*/_interopNamespaceDefault(i3);

    const registerProps = () => {
        base.register('wm-camera', new Map([
            ['allowedit', { value: false, ...base.PROP_BOOLEAN }],
            ['capturetype', { value: 'IMAGE', ...base.PROP_STRING }],
            ['caption', { value: '', ...base.PROP_STRING }],
            ['class', base.PROP_STRING],
            ['correctorientation', { value: false, ...base.PROP_BOOLEAN }],
            ['datavalue', { value: '', ...base.PROP_STRING }],
            ['iconclass', { value: 'wm-sl-l sl-camera', ...base.PROP_STRING }],
            ['iconsize', { value: '2em', ...base.PROP_STRING }],
            ['imagequality', { value: 80, ...base.PROP_NUMBER }],
            ['imageencodingtype', { value: 'JPEG', ...base.PROP_STRING }],
            ['imagetargetwidth', base.PROP_NUMBER],
            ['imagetargetheight', base.PROP_NUMBER],
            ['localFile', { value: '', ...base.PROP_STRING }],
            ['localFilePath', { value: '', ...base.PROP_STRING }],
            ['name', base.PROP_STRING],
            ['savetogallery', { value: false, ...base.PROP_BOOLEAN }],
            ['show', { value: true, ...base.PROP_BOOLEAN }],
            ['hint', base.PROP_STRING],
            ['arialabel', base.PROP_STRING]
        ]));
    };

    const _c0 = ["wmCamera", ""];
    const _c1 = a0 => ({ "font-size": a0 });
    const DEFAULT_CLS = 'btn app-camera';
    const WIDGET_CONFIG = { widgetType: 'wm-camera', hostClass: DEFAULT_CLS };
    exports.CAPTURE_TYPE = void 0;
    (function (CAPTURE_TYPE) {
        CAPTURE_TYPE["IMAGE"] = "IMAGE";
        CAPTURE_TYPE["PNG"] = "PNG";
    })(exports.CAPTURE_TYPE || (exports.CAPTURE_TYPE = {}));
    exports.ENCODING_TYPE = void 0;
    (function (ENCODING_TYPE) {
        ENCODING_TYPE["JPEG"] = "JPEG";
        ENCODING_TYPE["PNG"] = "PNG";
    })(exports.ENCODING_TYPE || (exports.ENCODING_TYPE = {}));
    class CameraComponent extends base.StylableComponent {
        static { this.initializeProps = registerProps(); }
        constructor(camera, mediaCapture, inj, elRef, cdr, explicitContext) {
            super(inj, WIDGET_CONFIG, explicitContext);
            this.camera = camera;
            this.mediaCapture = mediaCapture;
            base.styler(this.nativeElement, this, base.APPLY_STYLES_TYPE.SCROLLABLE_CONTAINER);
        }
        openCamera($event) {
            if (core.hasCordova()) {
                if (this.capturetype === exports.CAPTURE_TYPE.IMAGE) {
                    this._cameraOptions = {
                        quality: this.imagequality,
                        destinationType: 1, // 0-data url,1- file url
                        sourceType: 1, // only camera
                        allowEdit: this.allowedit,
                        correctOrientation: this.correctorientation,
                        encodingType: this.imageencodingtype === exports.ENCODING_TYPE.JPEG ? 0 : 1,
                        saveToPhotoAlbum: this.savetogallery,
                        targetWidth: this.imagetargetwidth,
                        targetHeight: this.imagetargetheight
                    };
                    // start camera
                    this.camera.getPicture(this._cameraOptions)
                        .then(path => this.updateModel($event, path));
                }
                else {
                    this._cameraOptions = {
                        limit: 1
                    };
                    // start video capture
                    this.mediaCapture.captureVideo(this._cameraOptions)
                        .then(mediaFiles => this.updateModel($event, mediaFiles[0].fullPath));
                }
            }
            else {
                this.invokeEventCallback('success', { $event });
            }
        }
        updateModel($event, value) {
            value = (value.startsWith('file://') ? '' : 'file://') + value;
            this.localFilePath = this.datavalue = value;
            core.convertToBlob(value)
                .then(result => {
                this.localFile = result.blob;
                this.invokeEventCallback('success', { $event, localFilePath: this.localFilePath, localFile: this.localFile });
            }, () => {
                this.localFile = undefined;
            });
        }
        static { this.ɵfac = function CameraComponent_Factory(t) { return new (t || CameraComponent)(i0__namespace.ɵɵdirectiveInject(i1__namespace.Camera), i0__namespace.ɵɵdirectiveInject(i2__namespace.MediaCapture), i0__namespace.ɵɵdirectiveInject(i0__namespace.Injector), i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef), i0__namespace.ɵɵdirectiveInject(i0__namespace.ChangeDetectorRef), i0__namespace.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
        static { this.ɵcmp = /*@__PURE__*/ i0__namespace.ɵɵdefineComponent({ type: CameraComponent, selectors: [["button", "wmCamera", ""]], hostBindings: function CameraComponent_HostBindings(rf, ctx) { if (rf & 1) {
                i0__namespace.ɵɵlistener("click", function CameraComponent_click_HostBindingHandler($event) { return ctx.openCamera($event); });
            } }, exportAs: ["wmCamera"], features: [i0__namespace.ɵɵProvidersFeature([
                    base.provideAsWidgetRef(CameraComponent)
                ]), i0__namespace.ɵɵInheritDefinitionFeature], attrs: _c0, decls: 1, vars: 4, consts: [[3, "ngClass", "ngStyle"]], template: function CameraComponent_Template(rf, ctx) { if (rf & 1) {
                i0__namespace.ɵɵelement(0, "i", 0);
            } if (rf & 2) {
                i0__namespace.ɵɵproperty("ngClass", ctx.iconclass)("ngStyle", i0__namespace.ɵɵpureFunction1(2, _c1, ctx.iconsize));
            } }, dependencies: [i3__namespace.NgClass, i3__namespace.NgStyle], encapsulation: 2 }); }
    }
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(CameraComponent, [{
            type: i0.Component,
            args: [{ selector: 'button[wmCamera]', providers: [
                        base.provideAsWidgetRef(CameraComponent)
                    ], exportAs: 'wmCamera', template: "<i [ngClass]=\"iconclass\" [ngStyle]=\"{'font-size': iconsize}\"></i>" }]
        }], () => [{ type: i1__namespace.Camera }, { type: i2__namespace.MediaCapture }, { type: i0__namespace.Injector }, { type: i0__namespace.ElementRef }, { type: i0__namespace.ChangeDetectorRef }, { type: undefined, decorators: [{
                    type: i0.Inject,
                    args: ['EXPLICIT_CONTEXT']
                }, {
                    type: i0.Optional
                }] }], { openCamera: [{
                type: i0.HostListener,
                args: ['click', ['$event']]
            }] }); })();
    (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassDebugInfo(CameraComponent, { className: "CameraComponent", filePath: "camera.component.ts", lineNumber: 32 }); })();

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

    exports.CameraComponent = CameraComponent;
    exports.CameraModule = CameraModule;

}));
