import { __decorate } from "tslib";
import { Component, Input, Output, EventEmitter, ViewChildren } from '@angular/core';
let NclexExamCalculatorComponent = class NclexExamCalculatorComponent {
    constructor() {
        this.expression = '0';
        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 = '0';
                break;
            case 'M+':
                this.memoryPlus = isNaN(parseInt(this.memory))
                    ? ''
                    : parseInt(this.memory) + '+';
                if (this.memoryPlus !== '') {
                    this.expression = this.memoryPlus;
                }
                break;
            case 'M-':
                this.memoryMinus = isNaN(parseInt(this.memory))
                    ? ''
                    : parseInt(this.memory) + '-';
                if (this.memoryMinus !== '') {
                    this.expression = this.memoryMinus;
                }
                break;
            case 'MR':
                if (this.memory !== undefined && this.memory !== '') {
                    this.expression = this.memory;
                }
                break;
            case 'MC':
                this.memory = '';
                this.expression = '0';
                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;
            case '±':
                const format = /[ !@#$%^&*()_+\-=\[\]{};':'\\|,<>\/?]/;
                const expLength = this.expression.length;
                if (expLength > 0 && !format.test(this.expression)) {
                    this.expression = String(Number(this.expression) * -1);
                }
                else if (expLength > 0 && format.test(this.expression)) {
                    console.log('this.expression.substring(1,expLength - 1)    ', this.expression.substring(1));
                    if (expLength === 1 && this.expression === '-') {
                        this.memory = '';
                        this.expression = '';
                    }
                    else if (!format.test(this.expression.charAt(expLength - 1))) {
                        if (this.expression.charAt(0) === '-' &&
                            !format.test(this.expression.substring(1))) {
                            this.expression = this.expression.substring(1);
                        }
                        else {
                            const temp = this.expression.charAt(expLength - 1);
                            this.expression =
                                this.expression.substring(0, expLength - 1) + '-' + temp;
                        }
                    }
                }
                else {
                    this.memory = '-';
                    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;
        }
        this.vc.first.nativeElement.focus();
    }
    /**
     * 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
     */
    validateUserInput(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([
    ViewChildren('input')
], NclexExamCalculatorComponent.prototype, "vc", void 0);
__decorate([
    Input()
], NclexExamCalculatorComponent.prototype, "resetFeature", void 0);
__decorate([
    Output()
], NclexExamCalculatorComponent.prototype, "updateResetValue", void 0);
NclexExamCalculatorComponent = __decorate([
    Component({
        selector: 'wkqp-nclex-exam-calculator',
        template: "<div class=\"qp-feature-menu\">\n  <div class=\"calculator-menu\">\n    <button\n      (click)=\"showCalculatorDialogBox()\"\n      style=\"\n      background: none;\n  \"\n    >\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    <div class=\"calculator-modal\" *ngIf=\"calculatorOpen && !resetFeature\">\n      <div\n        id=\"calcuLatorMain\"\n        class=\"calcuLator-wrapper ember-view draggable-area nclex-calc-outer\"\n        cdkDrag\n      >\n        <div class=\"ember-view calcuLator\">\n          <img\n            alt=\"Dialog-close\"\n            (click)=\"closeCal()\"\n            src=\"assets/engine-icons/calculator-close-icon.png\"\n            class=\"calc-close\"\n            aria-hidden=\"true\"\n          />\n\n          <div class=\"calcuLator-main\">\n            <table style=\"margin-top:15px;height: 100%;\">\n              <tr>\n                <td colspan=\"4\">\n                  <input\n                    #input\n                    (keydown)=\"validateUserInput($event)\"\n                    type=\"text\"\n                    class=\"calc-textbox\"\n                    style=\"text-align: right\"\n                    [(ngModel)]=\"expression\"\n                  />\n                </td>\n              </tr>\n              <tr>\n                <td>\n                  <input\n                    (click)=\"concatNumber('MC')\"\n                    class=\"btn-normal calc-btn-color1\"\n                    type=\"button\"\n                    value=\"mc\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('M+')\"\n                    class=\"btn-normal calc-btn-color1\"\n                    type=\"button\"\n                    value=\"m+\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('M-')\"\n                    class=\"btn-normal calc-btn-color1\"\n                    type=\"button\"\n                    value=\"m-\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('MR')\"\n                    class=\"btn-normal calc-btn-color1\"\n                    type=\"button\"\n                    value=\"mr\"\n                  />\n                </td>\n              </tr>\n              <tr>\n                <td>\n                  <input\n                    (click)=\"concatNumber('CE')\"\n                    class=\"btn-normal calc-btn-color2\"\n                    type=\"button\"\n                    value=\"AC\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('\u00B1')\"\n                    class=\"btn-normal calc-btn-color2\"\n                    type=\"button\"\n                    value=\"+/-\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('/')\"\n                    class=\"btn-normal calc-btn-color2\"\n                    type=\"button\"\n                    value=\"&divide;\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('*')\"\n                    class=\"btn-normal calc-btn-color2\"\n                    type=\"button\"\n                    value=\"&times;\"\n                  />\n                </td>\n              </tr>\n              <tr>\n                <td>\n                  <input\n                    (click)=\"concatNumber('7')\"\n                    class=\"btn-normal calc-btn\"\n                    type=\"button\"\n                    value=\"7\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('8')\"\n                    class=\"btn-normal calc-btn\"\n                    type=\"button\"\n                    value=\"8\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('9')\"\n                    class=\"btn-normal calc-btn\"\n                    type=\"button\"\n                    value=\"9\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('-')\"\n                    class=\"btn-normal calc-btn-color2\"\n                    type=\"button\"\n                    value=\"-\"\n                  />\n                </td>\n              </tr>\n              <tr>\n                <td>\n                  <input\n                    (click)=\"concatNumber('4')\"\n                    class=\"btn-normal calc-btn\"\n                    type=\"button\"\n                    value=\"4\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('5')\"\n                    class=\"btn-normal calc-btn\"\n                    type=\"button\"\n                    value=\"5\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('6')\"\n                    class=\"btn-normal calc-btn\"\n                    type=\"button\"\n                    value=\"6\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('+')\"\n                    class=\"btn-normal calc-btn-color2\"\n                    type=\"button\"\n                    value=\"+\"\n                  />\n                </td>\n              </tr>\n              <tr>\n                <td>\n                  <input\n                    (click)=\"concatNumber('1')\"\n                    class=\"btn-normal calc-btn\"\n                    type=\"button\"\n                    value=\"1\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('2')\"\n                    class=\"btn-normal calc-btn\"\n                    type=\"button\"\n                    value=\"2\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('3')\"\n                    class=\"btn-normal calc-btn\"\n                    type=\"button\"\n                    value=\"3\"\n                  />\n                </td>\n                <td rowspan=\"2\">\n                  <input\n                    type=\"button\"\n                    (click)=\"operation()\"\n                    class=\"btn-equal\"\n                    value=\"=\"\n                  />\n                </td>\n              </tr>\n              <tr>\n                <td colspan=\"2\">\n                  <input\n                    class=\"btn-normal calc-btn\"\n                    (click)=\"concatNumber('0')\"\n                    type=\"button\"\n                    value=\"0\"\n                  />\n                </td>\n                <td>\n                  <input\n                    (click)=\"concatNumber('.')\"\n                    class=\"btn-normal calc-btn\"\n                    type=\"button\"\n                    value=\".\"\n                  />\n                </td>\n              </tr>\n            </table>\n          </div>\n        </div>\n      </div>\n    </div>\n  </div>\n</div>\n",
        styles: [".clear-box{float:left;width:100%}.calculator-block{margin-bottom:2vh!important}.header-child-wrapper{float:left;width:100%;background-color:#1d6ea775;padding-bottom:3px}.engine-header-record-column-nclex{width:auto;padding:0;display:block}.btn-icon{background:0 0;padding:0;margin-top:1vh}.btn-icon:hover{background:0 0!important}.child-header-body{color:#ffff;margin:1vw 0 0 1vw;font-size:1.25vw}.fa-calculator:before{content:\"\\f1ec\"}.calculator-modal{right:inherit;top:46px;left:0;position:absolute;width:260px;z-index:100000}.wkqp-row .test-header1{width:17%}.wkqp-row .test-header2{width:14%}.wkqp-row .test-header3{width:6%}.wkqp-row .test-header4{width:7%}.wkqp-row .test-header5{width:10%}.wkqp-row .test-header6{width:15%}.wkqp-row .test-header7{width:11%}.wkqp-row .test-header8{width:7%}.nclex-calc-outer{background-color:#000!important;border-radius:8px!important}.cal-btn-row{margin-bottom:9px}.nclex-calc-modal{width:200px;height:250px;background:0 0}.nclex-calc-modal-body{background-color:#000}.title{margin-bottom:10px;text-align:center;width:210px;color:#515451;border:2px solid #000}input[type=button]{color:#fff;border:2px solid #000;height:25px;border-radius:5px;padding:1px;box-shadow:inset 0 1px 9px -3px!important;font-size:12px!important;font-weight:700!important}.modal-body{position:relative!important;padding:10px!important}.btn-equal{height:9vh!important;background-color:#d87005!important;margin:-2px 0 0!important}.btn-equal:hover{border:2px solid #000!important}.calc-close{margin:0!important;position:absolute;top:1px;right:2px}.calcuLatorHeader{padding:10px;cursor:move;z-index:10;background-color:#000;color:#fff}.calcuLator-header{height:22px;display:flex;justify-content:center;align-items:center;position:relative;background-color:#000;color:#fff;font-family:arial,sans-serif;font-size:14px;font-weight:700;border-radius:15px}.calcuLator-header .calcuLator-close{position:absolute;top:50%;transform:translate(0,-50%);right:3px}.wk-alert-dismissible.newalertdismissible .wk-icon-close-empty{position:static;float:right;margin:-17px -15px 0 0}.calcuLator-close{cursor:pointer}.calcuLator-main{padding:1px 10px 20px;background-color:#000;border-radius:10px;height:270px;margin-top:0}.calcuLator-main .calcuLator-display{margin-bottom:7px}.calc-textbox{background-color:#e4e4d1!important;border-radius:6px!important;width:100%;border:none!important;box-shadow:inset 0 -9px 28px -4px #999c65;font-size:35px!important;font-weight:700!important}.calcuLator-display input{background-color:#eef7f6!important;font-weight:700}.calcuLator-buttons{display:flex;flex-wrap:wrap;margin-right:-7px;margin-bottom:-7px}.calcuLator-buttons .calcuLator-button{width:calc(20% - 7px);height:30px;margin-right:7px;margin-bottom:7px}.calcuLator-button:hover,.calcuLator-buttons:hover{color:#000}.calcuLator-buttons .calcuLator-button._equal{width:calc(40% - 7px);background-color:#cc5c0d!important}.calcuLator-buttons .calcuLator-button._add{height:67px;margin-bottom:-30px}.btn-normal{width:95%;height:0;border-radius:3px;padding:11px;background-color:#2d2c2c;line-height:0}.btn-normal:hover{border:2px solid #000!important}.calc-btn-color1{background-color:#647179!important}.calc-btn-color2{background-color:#352323!important}.calc-btn{background-color:#000!important}.calcuLator-button._memory{background-color:#76718f;border-color:#adaabc;color:#fff;padding-top:8px;padding-left:9px}.calcuLator-button._clear{background-color:#f4b74c;border-color:#fadeac;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}.examTaker-header-region-right-inner .examTaker-nav-button._calc .examTaker-nav-button-icon,.examTaker-header-region-right-inner .examTaker-nav-button._lab .examTaker-nav-button-icon,.examTaker-header-region-right-inner .examTaker-nav-button._notes .examTaker-nav-button-icon,.examTaker-header-region-right-inner .examTaker-nav-button._reverse .examTaker-nav-button-icon,.examTaker-header-region-right-inner .examTaker-nav-button._text_zoom .examTaker-nav-button-icon{margin-bottom:3px}.calculator-menu{position:relative}.calculator-menu button{padding:0;color:#474747;text-align:center;background-color:transparent}.calculator-menu button span{color:#474747;text-align:center;display:block;font-size:14px}.pt3{padding-top:3px}"]
    })
], NclexExamCalculatorComponent);
export { NclexExamCalculatorComponent };
//# sourceMappingURL=data:application/json;base64, 