(function (paw, utils) {
  function SysInfoComponent($elt) {
    var self = this;

    this.sysInfo;
    this.auth;
    this.additionalData;
    this.localization;

    this.$elt = $elt;

    this.licenceInfoProps = [
      {
        label: "RegisteredUser",
        propId: "registeredUser",
      },
      {
        label: "SerialNumber",
        propId: "serialNumber",
      },
      {
        label: "License",
        propId: "quantity",
        format: (value, model) => {
          return `${value} / ${self.additionalData.domainLicenceTotal}`;
        },
      },
    ];
  }

  SysInfoComponent.prototype.markupDef = function () {
    var markup = [];
    console.log("Sys info", this.sysInfo);
    markup.push('<div class="paw-area-v paw-nooverflow sys-info">');
    markup.push('  <div class="paw-col-d paw-scrollable">');
    markup.push('    <div class="sys-info-panel">');
    markup.push('      <div class="sys-info-panel-title">');
    markup.push("        <span>" + this.localization.licenceInfo + "</span>");
    markup.push("      </div>");
    markup.push("      <div>");
    markup = markup.concat(
      this.markupSysProps(this.licenceInfoProps, this.sysInfo.licenceInfo)
    );
    markup.push("      </div>");
    markup.push("    </div>");
    markup.push("");
    markup.push('    <div class="sys-info-panel sys-info-panel-version-info">');
    markup.push('      <div class="sys-info-panel-title">');
    markup.push("        <span>" + this.localization.versionInfo + "</span>");
    markup.push("      </div>");
    markup.push("      <div>");
    markup = markup.concat(
      this.markupSysProps(this.versionInfoProps, this.sysInfo.versionInfo)
    );
    markup.push("      </div>");
    markup.push("    </div>");
    markup.push("  </div>");
    markup.push('  <div class="paw-col sys-info-copyright">');
    markup.push("    <span>" + this.localization.copyright + "</span>");
    markup.push("  </div>");
    markup.push("</div>");
    return markup;
  };

  SysInfoComponent.prototype.markupSysProps = function (props, model) {
    var self = this;
    var markup = [];
    utils.iterable.iterate(props, function (prop) {
      if (prop.allowed === false) {
        console.log("Allowed", prop);
        return;
      }
      markup.push('  <div class="row">');
      markup.push('    <div class="col-md-5 sys-info-prop-label">');
      markup.push("      <span>" + self.localization[prop.label] + "</span>");
      markup.push("    </div>");
      markup.push('    <div class="col-md-7 paw-nooverflow">');
      markup.push(
        "      <span>" + self.formatPropValue(model, prop) + "</span>"
      );
      markup.push("    </div>");
      markup.push("  </div>");
    });
    return markup;
  };

  SysInfoComponent.prototype.formatPropValue = function (model, prop) {
    var value = model[prop.propId];
    return prop.format ? prop.format(value, model, prop) : value;
  };

  SysInfoComponent.prototype.onBinded = function () {
    var self = this;
    this.versionInfoProps = [
      {
        label: "VersionWeb",
        propId: "webBuildVersionView",
        format: (value, model) => {
          return `${value} rev. ${model.webBuildRevision}`;
        },
      },
      {
        label: "VersionDB",
        propId: "dbBuildVersionView",
        format: (value, model) => {
          return `${value} rev. ${model.revision}`;
        },
      },
      {
        label: "Branch",
        propId: "branch",
      },
      {
        label: "Commit",
        propId: "commit",
      },
      {
        label: "Database",
        propId: "databaseName",
      },
      {
        label: "Legislation",
        propId: "legislation",
      },
      {
        label: "CollationDB",
        propId: "collationDb",
      },
      {
        label: "CollationServer",
        propId: "collationServer",
      },
      // only for admin
      {
        label: "PaasVersion",
        propId: "paasVersion",
        allowed: this.auth["paasProps"],
      },
      {
        label: "PaasLocalization",
        propId: "paasLocalization",
        allowed: this.auth["paasProps"],
      },
      {
        label: "PaasIP",
        propId: "paasIP",
        allowed: this.auth["paasProps"],
      },
      // only for SR loc
      {
        label: "ESIRVersion",
        propId: "esirVersion",
        allowed: this.auth["esirVersion"],
        format: (value, model) => {
          return this.localization.EsirVersionDatalab.replace(
            "{version}",
            self.additionalData.esirVersion
          );
        },
      },
      // only for HR loc
      {
        label: "MaxCashPayment",
        propId: "maxCashPayment",
        allowed: this.auth["maxCashPayment"],
      },
    ];
  };

  SysInfoComponent.prototype.destroy = function () {};

  SysInfoComponent.prototype.onResize = function () {};

  paw.com.sysInfo.SysInfoComponent = SysInfoComponent;
})(paw, paw.utils);
