import * as i0 from '@angular/core';
import { Directive, Input } from '@angular/core';
import * as i1 from '@ironsource/fusion-ui/pipes/string';
import { isNullOrUndefined } from '@ironsource/fusion-ui/utils';

var MobileOrientation;
(function (MobileOrientation) {
    MobileOrientation[MobileOrientation["ALL"] = 0] = "ALL";
    MobileOrientation[MobileOrientation["PORTRAIT"] = 1] = "PORTRAIT";
    MobileOrientation[MobileOrientation["LANDSCAPE"] = 2] = "LANDSCAPE";
})(MobileOrientation || (MobileOrientation = {}));

const WIDTH_STATIC = '568';
const HEIGHT_STATIC = '320';
const BORDER_WIDTH = 2.6;
const DEVICE_ORIENTATION = ['tablet-portrait', 'tablet-landscape', 'phone-portrait', 'phone-landscape'];

class MobilePreviewerBaseComponent {
    set configurations(configurations) {
        this._configurations = configurations;
        this.isStaticSize =
            !isNullOrUndefined(configurations?.staticComponentSize?.height) ||
                !isNullOrUndefined(configurations?.staticComponentSize?.width);
        if (this.isStaticSize) {
            this._configurations.staticComponentSize.width = configurations.staticComponentSize.width || WIDTH_STATIC;
            this._configurations.staticComponentSize.height = configurations.staticComponentSize.height || HEIGHT_STATIC;
        }
        switch (this._configurations.orientation) {
            case MobileOrientation.PORTRAIT:
                this.devices = DEVICE_ORIENTATION.filter(device => device.includes('portrait'));
                break;
            case MobileOrientation.LANDSCAPE:
                this.devices = DEVICE_ORIENTATION.filter(device => device.includes('landscape'));
                break;
            case MobileOrientation.ALL:
            default:
                this.devices = DEVICE_ORIENTATION;
                break;
        }
    }
    get configurations() {
        return this._configurations;
    }
    get selectedDevice() {
        return this._capitalizePipe.transform(this._selectedDevice.replace('-', ' '));
    }
    get staticHeight() {
        return Number(this._configurations?.staticComponentSize?.height);
    }
    get height() {
        let height;
        switch (this._selectedDevice) {
            case 'phone-portrait':
                height = 568;
                break;
            case 'phone-landscape':
                height = 320;
                break;
            case 'tablet-portrait':
                height = 614;
                break;
            case 'tablet-landscape':
                height = 461;
                break;
        }
        return height;
    }
    get width() {
        let width;
        switch (this._selectedDevice) {
            case 'phone-portrait':
                width = 320;
                break;
            case 'phone-landscape':
                width = 568;
                break;
            case 'tablet-portrait':
                width = 461;
                break;
            case 'tablet-landscape':
                width = 614;
                break;
        }
        return width;
    }
    get calculatedContentSize() {
        const ratio = this.width / this.height;
        return {
            width: Math.floor((this.staticHeight - this.borderWidth) * ratio) + 1,
            height: Math.floor(this.staticHeight - this.borderWidth)
        };
    }
    constructor(elementRef, _capitalizePipe) {
        this.elementRef = elementRef;
        this._capitalizePipe = _capitalizePipe;
        this._configurations = { component: { type: null } };
        this._selectedDevice = '';
        this.isStaticSize = false;
        this.refresh = true;
        this.borderWidth = BORDER_WIDTH;
    }
    ngOnInit() {
        this._selectedDevice = this.configurations.orientation === MobileOrientation.PORTRAIT ? 'phone-portrait' : 'phone-landscape';
    }
    isDeviceSelected(device) {
        return this._selectedDevice === device;
    }
    isDeviceLandscape(device) {
        return device.includes('landscape');
    }
    selectDevice(device) {
        this._selectedDevice = device;
        this.refresh = !this.refresh;
    }
    static { this.ɵfac = function MobilePreviewerBaseComponent_Factory(t) { return new (t || MobilePreviewerBaseComponent)(i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(i1.CapitalizePipe)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: MobilePreviewerBaseComponent, inputs: { configurations: "configurations" } }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MobilePreviewerBaseComponent, [{
        type: Directive
    }], () => [{ type: i0.ElementRef }, { type: i1.CapitalizePipe }], { configurations: [{
            type: Input
        }] }); })();

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

export { BORDER_WIDTH, DEVICE_ORIENTATION, HEIGHT_STATIC, MobileOrientation, MobilePreviewerBaseComponent, WIDTH_STATIC };
//# sourceMappingURL=ironsource-fusion-ui-components-mobile-previewer-common-base.mjs.map
