import { Component, Element, h, Prop, State } from "@stencil/core";
import { Merchant } from "@payfunc/model-acquirer";
import * as translation from "../translation";
export class IntergiroMerchantFooter {
  componentWillLoad() {
    this.t = translation.create(this.element);
  }
  downloadCsv() {
    const file = this.merchants
      ? Merchant.toCsv(this.merchantsSelected && this.merchantsSelected.length != 0 ? this.merchantsSelected : this.merchants)
      : "";
    const link = document.createElement("a");
    link.setAttribute("href", "data:text/csv;charset=utf-8," + encodeURIComponent(file));
    link.setAttribute("download", "merchants.csv");
    link.style.display = "none";
    document.body.appendChild(link);
    link.click();
    link.remove();
  }
  render() {
    var _a, _b, _c, _d, _e;
    return [
      h("smoothly-display", null, this.t(this.merchantsSelected && ((_a = this.merchantsSelected) === null || _a === void 0 ? void 0 : _a.length) != 0 ? "selected count:" : "total count:")),
      h("smoothly-display", null, this.merchantsSelected && ((_b = this.merchantsSelected) === null || _b === void 0 ? void 0 : _b.length) != 0
        ? (_c = this.merchantsSelected) === null || _c === void 0 ? void 0 : _c.length
        : (_e = (_d = this.merchants) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0),
      h("smoothly-icon", { hidden: this.merchants == undefined, onClick: () => this.downloadCsv(), color: "light", toolTip: this.t("Download merchant details"), name: "cloud-download" }),
    ];
  }
  static get is() { return "ig-merchant-footer"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["style.css"]
  }; }
  static get styleUrls() { return {
    "$": ["style.css"]
  }; }
  static get properties() { return {
    "merchants": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Merchant[]",
        "resolved": "Merchant[] | undefined",
        "references": {
          "Merchant": {
            "location": "import",
            "path": "@payfunc/model-acquirer"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "merchantsSelected": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Merchant[]",
        "resolved": "Merchant[] | undefined",
        "references": {
          "Merchant": {
            "location": "import",
            "path": "@payfunc/model-acquirer"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "t": {}
  }; }
  static get elementRef() { return "element"; }
}
