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

const registerProps = () => {
    register('wm-camera', new Map([
        ['allowedit', { value: false, ...PROP_BOOLEAN }],
        ['capturetype', { value: 'IMAGE', ...PROP_STRING }],
        ['caption', { value: '', ...PROP_STRING }],
        ['class', PROP_STRING],
        ['correctorientation', { value: false, ...PROP_BOOLEAN }],
        ['datavalue', { value: '', ...PROP_STRING }],
        ['iconclass', { value: 'wm-sl-l sl-camera', ...PROP_STRING }],
        ['iconsize', { value: '2em', ...PROP_STRING }],
        ['imagequality', { value: 80, ...PROP_NUMBER }],
        ['imageencodingtype', { value: 'JPEG', ...PROP_STRING }],
        ['imagetargetwidth', PROP_NUMBER],
        ['imagetargetheight', PROP_NUMBER],
        ['localFile', { value: '', ...PROP_STRING }],
        ['localFilePath', { value: '', ...PROP_STRING }],
        ['name', PROP_STRING],
        ['savetogallery', { value: false, ...PROP_BOOLEAN }],
        ['show', { value: true, ...PROP_BOOLEAN }],
        ['hint', PROP_STRING],
        ['arialabel', 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 };
var CAPTURE_TYPE;
(function (CAPTURE_TYPE) {
    CAPTURE_TYPE["IMAGE"] = "IMAGE";
    CAPTURE_TYPE["PNG"] = "PNG";
})(CAPTURE_TYPE || (CAPTURE_TYPE = {}));
var ENCODING_TYPE;
(function (ENCODING_TYPE) {
    ENCODING_TYPE["JPEG"] = "JPEG";
    ENCODING_TYPE["PNG"] = "PNG";
})(ENCODING_TYPE || (ENCODING_TYPE = {}));
class CameraComponent extends StylableComponent {
    static { this.initializeProps = registerProps(); }
    constructor(camera, mediaCapture, inj, elRef, cdr, explicitContext) {
        super(inj, WIDGET_CONFIG, explicitContext);
        this.camera = camera;
        this.mediaCapture = mediaCapture;
        styler(this.nativeElement, this, APPLY_STYLES_TYPE.SCROLLABLE_CONTAINER);
    }
    openCamera($event) {
        if (hasCordova()) {
            if (this.capturetype === 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 === 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;
        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.ɵɵdirectiveInject(i1.Camera), i0.ɵɵdirectiveInject(i2.MediaCapture), i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject('EXPLICIT_CONTEXT', 8)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: CameraComponent, selectors: [["button", "wmCamera", ""]], hostBindings: function CameraComponent_HostBindings(rf, ctx) { if (rf & 1) {
            i0.ɵɵlistener("click", function CameraComponent_click_HostBindingHandler($event) { return ctx.openCamera($event); });
        } }, exportAs: ["wmCamera"], features: [i0.ɵɵProvidersFeature([
                provideAsWidgetRef(CameraComponent)
            ]), i0.ɵɵInheritDefinitionFeature], attrs: _c0, decls: 1, vars: 4, consts: [[3, "ngClass", "ngStyle"]], template: function CameraComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelement(0, "i", 0);
        } if (rf & 2) {
            i0.ɵɵproperty("ngClass", ctx.iconclass)("ngStyle", i0.ɵɵpureFunction1(2, _c1, ctx.iconsize));
        } }, dependencies: [i3.NgClass, i3.NgStyle], encapsulation: 2 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CameraComponent, [{
        type: Component,
        args: [{ selector: 'button[wmCamera]', providers: [
                    provideAsWidgetRef(CameraComponent)
                ], exportAs: 'wmCamera', template: "<i [ngClass]=\"iconclass\" [ngStyle]=\"{'font-size': iconsize}\"></i>" }]
    }], () => [{ type: i1.Camera }, { type: i2.MediaCapture }, { type: i0.Injector }, { type: i0.ElementRef }, { type: i0.ChangeDetectorRef }, { type: undefined, decorators: [{
                type: Inject,
                args: ['EXPLICIT_CONTEXT']
            }, {
                type: Optional
            }] }], { openCamera: [{
            type: HostListener,
            args: ['click', ['$event']]
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵ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.ɵɵdefineNgModule({ type: CameraModule }); }
    static { this.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule,
            WmComponentsModule] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CameraModule, [{
        type: NgModule,
        args: [{
                imports: [
                    CommonModule,
                    WmComponentsModule
                ],
                declarations: [...components],
                exports: [...components]
            }]
    }], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(CameraModule, { declarations: [CameraComponent], imports: [CommonModule,
        WmComponentsModule], exports: [CameraComponent] }); })();

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

export { CAPTURE_TYPE, CameraComponent, CameraModule, ENCODING_TYPE };
//# sourceMappingURL=index.mjs.map
