import { __decorate } from "tslib";
import { Component, Output, Input, EventEmitter } from '@angular/core';
let UsmleExamCalculatorComponent = class UsmleExamCalculatorComponent {
    constructor() {
        this.expression = '';
        this.updateResetValue = new EventEmitter();
    }
    ngOnChanges(changes) {
        if (this.resetFeature) {
            this.calculatorOpen = false;
        }
    }
    ngOnInit() { }
    /**
     * Close the calculator
     */
    closeCal() {
        this.calculatorOpen = false;
    }
    /**
     * Concat the expression in the calculator
     * @param calcValue
     */
    concatNumber(calcValue) {
        switch (calcValue) {
            case 'CE':
                this.expression = '';
                break;
            case 'M+':
                this.memoryPlus = isNaN(parseInt(this.memory))
                    ? ''
                    : parseInt(this.memory) + '+';
                if (this.memoryPlus !== '') {
                    this.expression = this.memoryPlus;
                }
                break;
            case 'MR':
                if (this.memory !== undefined && this.memory !== '') {
                    this.expression = this.memory;
                }
                break;
            case 'MC':
                this.memory = '';
                this.expression = '';
                break;
            case 'C':
                const splitted = this.expression.toString().slice(0, -1);
                this.expression = splitted;
                break;
            case 'sqrt':
                this.expression = String(Math.sqrt(parseInt(this.expression)));
                break;
            default:
                if (this.expression.length === 1 &&
                    this.expression === '0' &&
                    (calcValue === '+' || calcValue === '/' || calcValue === '*')) {
                    this.expression = '';
                }
                else {
                    if (this.expression.length === 1 && this.expression === '0') {
                        this.expression = calcValue;
                    }
                    else {
                        this.expression += calcValue;
                    }
                }
                break;
        }
    }
    /**
     * Arithemetic operation
     */
    operation() {
        if (this.expression.length === 0) {
            return false;
        }
        this.expression = eval(this.expression);
        this.memory = this.expression;
        return this.expression;
    }
    /**
     * validating display expression
     * @param event
     */
    validateKey(event) {
        const calcValue = event.key;
        const restrictedKeys = [186, 187, 188, 192, 220, 222];
        const condition1 = event.which && event.which >= 65 && event.which <= 90;
        const condition2 = this.expression.length === 0 &&
            (calcValue === '+' ||
                calcValue === '/' ||
                calcValue === '*' ||
                calcValue === '=');
        if (condition1 || condition2 || restrictedKeys.indexOf(event.which) >= 0) {
            return false;
        }
        if (this.expression.length === 1 && this.expression === '0') {
            this.expression = '';
        }
    }
    /**
     * to show calculator dialog box
     */
    showCalculatorDialogBox() {
        this.updateResetValue.emit();
        this.calculatorOpen = !this.calculatorOpen;
    }
};
__decorate([
    Input()
], UsmleExamCalculatorComponent.prototype, "resetFeature", void 0);
__decorate([
    Output()
], UsmleExamCalculatorComponent.prototype, "updateResetValue", void 0);
UsmleExamCalculatorComponent = __decorate([
    Component({
        selector: 'wkqp-usmle-exam-calculator',
        template: "<div class=\"qp-feature-menu\">\n  <div class=\"calculator-menu\">\n    <button style=\"background: none;\" (click)=\"showCalculatorDialogBox()\">\n      <span>\n        <img\n          alt=\"Calculator\"\n          class=\"examTaker-nav-button-icon\"\n          src=\"./assets/engine-icons/calculator-icon.png\"\n        />\n      </span>\n      <span class=\"pt3\">Calculator</span>\n    </button>\n\n    <!--Calculator Content-->\n    <div\n      *ngIf=\"calculatorOpen && !resetFeature\"\n      class=\"calculator-modal\"\n      cdkDrag\n    >\n      <div\n        style=\"background-color:black;\"\n        id=\"calcuLatorMain\"\n        class=\"calcuLator-wrapper ember-view draggable-area\"\n      >\n        <div class=\"ember-view calcuLator\">\n          <div id=\"calcuLatorHeader\" class=\"calcuLator-header\">\n            <span>Calculator</span>\n          </div>\n          <img\n            alt=\"Dialog-close\"\n            (click)=\"closeCal()\"\n            src=\"assets/engine-icons/calculator-close-icon.png\"\n            class=\"wk-icon-close calc-close\"\n            aria-hidden=\"true\"\n          />\n          <div class=\"calcuLator-main\">\n            <div class=\"calcuLator-display\">\n              <input\n                type=\"text\"\n                name=\"display\"\n                id=\"display\"\n                [(ngModel)]=\"expression\"\n                (keydown)=\"validateKey($event)\"\n              />\n            </div>\n\n            <div class=\"calcuLator-buttons\">\n              <button\n                (click)=\"concatNumber('M+')\"\n                class=\"calcuLator-button _memory _memoryPlus\"\n                data-ember-action=\"2056\"\n              >\n                M+\n              </button>\n\n              <button\n                (click)=\"concatNumber('MR')\"\n                class=\"calcuLator-button _memory _memoryRecall\"\n                data-ember-action=\"2057\"\n              >\n                MR\n              </button>\n\n              <button\n                (click)=\"concatNumber('MC')\"\n                class=\"calcuLator-button _memory _memoryClear\"\n                data-ember-action=\"2058\"\n              >\n                MC\n              </button>\n\n              <button\n                (click)=\"concatNumber('CE')\"\n                class=\"calcuLator-button _clear _clearEntry\"\n                data-ember-action=\"2059\"\n              >\n                CE\n              </button>\n\n              <button\n                (click)=\"concatNumber('C')\"\n                class=\"calcuLator-button _clear _clearAll\"\n                data-ember-action=\"2060\"\n              >\n                C\n              </button>\n\n              <button\n                (click)=\"concatNumber('7')\"\n                class=\"calcuLator-button _number _7\"\n                data-ember-action=\"2061\"\n              >\n                7\n              </button>\n\n              <button\n                (click)=\"concatNumber('8')\"\n                class=\"calcuLator-button _number _8\"\n                data-ember-action=\"2062\"\n              >\n                8\n              </button>\n\n              <button\n                (click)=\"concatNumber('9')\"\n                class=\"calcuLator-button _number _9\"\n                data-ember-action=\"2063\"\n              >\n                9\n              </button>\n\n              <button\n                (click)=\"concatNumber('*')\"\n                class=\"calcuLator-button _operation _multiply\"\n                data-ember-action=\"2064\"\n              >\n                \u00D7\n              </button>\n\n              <button\n                (click)=\"concatNumber('-')\"\n                class=\"calcuLator-button _operation _subtract\"\n                data-ember-action=\"2065\"\n              >\n                \u2212\n              </button>\n\n              <button\n                (click)=\"concatNumber('4')\"\n                class=\"calcuLator-button _number _4\"\n                data-ember-action=\"2066\"\n              >\n                4\n              </button>\n\n              <button\n                (click)=\"concatNumber('5')\"\n                class=\"calcuLator-button _number _5\"\n                data-ember-action=\"2067\"\n              >\n                5\n              </button>\n\n              <button\n                (click)=\"concatNumber('6')\"\n                class=\"calcuLator-button _number _6\"\n                data-ember-action=\"2068\"\n              >\n                6\n              </button>\n\n              <button\n                (click)=\"concatNumber('/')\"\n                class=\"calcuLator-button _operation _divide\"\n                data-ember-action=\"2069\"\n              >\n                \u00F7\n              </button>\n\n              <button\n                (click)=\"concatNumber('+')\"\n                class=\"calcuLator-button _operation _add\"\n                data-ember-action=\"2070\"\n              >\n                +\n              </button>\n\n              <button\n                (click)=\"concatNumber('1')\"\n                class=\"calcuLator-button _number _1\"\n                data-ember-action=\"2071\"\n              >\n                1\n              </button>\n\n              <button\n                (click)=\"concatNumber('2')\"\n                class=\"calcuLator-button _number _2\"\n                data-ember-action=\"2072\"\n              >\n                2\n              </button>\n\n              <button\n                (click)=\"concatNumber('3')\"\n                class=\"calcuLator-button _number _3\"\n                data-ember-action=\"2073\"\n              >\n                3\n              </button>\n\n              <button\n                (click)=\"concatNumber('sqrt')\"\n                class=\"calcuLator-button _operation _sqrt\"\n                data-ember-action=\"2074\"\n              >\n                \u221A\n              </button>\n\n              <button class=\"calcuLator-button _filler\"></button>\n\n              <button\n                (click)=\"concatNumber('\u00B1')\"\n                class=\"calcuLator-button _operation _sign\"\n                data-ember-action=\"2075\"\n              >\n                \u00B1\n              </button>\n\n              <button\n                (click)=\"concatNumber('0')\"\n                class=\"calcuLator-button _number _0\"\n                data-ember-action=\"2076\"\n              >\n                0\n              </button>\n\n              <button\n                (click)=\"concatNumber('.')\"\n                class=\"calcuLator-button _number _dot\"\n                data-ember-action=\"2077\"\n              >\n                .\n              </button>\n\n              <button\n                class=\"calcuLator-button _operation _equal\"\n                data-ember-action=\"2078\"\n                (click)=\"operation()\"\n              >\n                =\n              </button>\n            </div>\n          </div>\n        </div>\n      </div>\n    </div>\n  </div>\n</div>\n",
        styles: [".calcuLator-header .wk-icon-close.calcuLator-close,.calcuLator-header .wk-icon-close.calcuLator-close:before{margin:0;font-size:16px;color:#fff}.examTaker-content .calcuLator-wrapper{z-index:9999}.examTaker-content .calcuLator-wrapper.draggable-area{position:absolute;bottom:1px;right:1px}.calcuLatorHeader{padding:10px;cursor:move;z-index:10;background-color:#2196f3;color:#fff}.calcuLator-header{height:22px;display:flex;justify-content:center;align-items:center;position:relative;border:0;background-color:var(--primary-color);color:#fff;font-family:arial,sans-serif;font-size:14px;font-weight:700}.calcuLator-header .calcuLator-close{position:absolute;top:50%;transform:translate(0,-50%);right:3px}.calcuLator-close{cursor:pointer}.calcuLator-main{padding:7px;background-color:#dadada}.calcuLator-main .calcuLator-display{margin-bottom:7px}.calcuLator-buttons{display:flex;flex-wrap:wrap;margin-right:-7px;margin-bottom:-7px}.calcuLator-button:hover,.calcuLator-buttons:hover{color:#000}.calcuLator-buttons .calcuLator-button._equal{width:calc(40% - 7px)}.calcuLator-buttons .calcuLator-button._add{height:67px;margin-bottom:-30px}.calcuLator-buttons .calcuLator-button{width:calc(20% - 7px);height:30px;margin-right:7px;margin-bottom:7px}.calcuLator-button._memory{color:#fff;padding-top:8px;padding-left:9px}.calcuLator-button._clear{font-weight:700;padding-top:8px;padding-left:9px}.calcuLator-button._number,.calcuLator-button._operation{font-size:1.2em;background-color:#fff;color:#000;padding-top:8px;padding-left:9px}.calcuLator-button._filler{visibility:hidden;pointer-events:none}.calculator-menu{position:relative}.calculator-menu button{padding:0;text-align:center}.calculator-menu button span{color:#474747;text-align:center;display:block;font-size:14px}.pt3{padding-top:3px}.calculator-modal{right:inherit;top:46px;left:0;position:absolute;width:260px;z-index:100000}.calc-close{margin:0!important;position:absolute;top:3px;right:5px}.ember-view.calcuLator{border:1px solid #000}.calcuLator-display input[type=text]{height:2rem;border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;border-top:1px solid #474747;border-left:1px solid #474747;line-height:normal;padding:3px 10px;text-align:right}button.calcuLator-button._memory._memoryClear,button.calcuLator-button._memory._memoryPlus,button.calcuLator-button._memory._memoryRecall{background-color:#716d89;border-bottom:1px solid #6b6974;border-right:1px solid #6b6974;border-top:1px solid #d4d3da;border-left:1px solid #d4d3da;color:#fff}button.calcuLator-button._clearAll,button.calcuLator-button._clearEntry{background-color:#eab049;border-bottom:1px solid #908164;border-right:1px solid #908164;border-top:1px solid #f3e9d8;border-left:1px solid #f3e9d8;color:#000}button.calcuLator-button._number,button.calcuLator-button._operation{background-color:#d0cfdc;border-bottom:1px solid #878787;border-right:1px solid #878787;border-top:1px solid #f5f5f5;border-left:1px solid #f5f5f5;color:#000}"]
    })
], UsmleExamCalculatorComponent);
export { UsmleExamCalculatorComponent };
//# sourceMappingURL=data:application/json;base64, 