import { Component, h, Host, Prop, State } from '@stencil/core';
import services from '../../configs/services';
export class DevingenProductApiKeysPage {
  constructor() {
    this.fetchProduct = async () => {
      const { id } = this.match.params;
      this.product = await this.apiDevingen.getProduct(id).catch((e) => this.error = e);
    };
    this.renderHeader = () => {
      var _a;
      return (h("div", { class: "container" },
        h("div", { class: "row" },
          h("div", { class: "col d-flex align-items-center pt-2 pb-3" },
            h("h2", { class: "m-0" }, (_a = this.product) === null || _a === void 0 ? void 0 :
              _a.name,
              " / API Key Settings")))));
    };
    this.generatePredefinedScopes = () => {
      const { product } = this;
      switch (product.type) {
        case 'damga':
          return [
            { label: 'Target Groups - Write', value: `dri:das:products:${product._id}:damga:target-groups:*.write` },
          ];
        case 'sepet':
          return [
            { label: 'Files - Write', value: `dri:das:products:${product._id}:sepet:files:*.write` },
            { label: 'Buckets - Write', value: `dri:das:products:${product._id}:sepet:buckets:*.write` },
          ];
      }
    };
  }
  componentWillLoad() {
    this.fetchProduct();
  }
  render() {
    const { product } = this;
    if (!product) {
      return (h("div", { class: "d-flex justify-content-center pt-3" },
        h("dvn-progress", { indefinite: true })));
    }
    const apiHeaders = {
      Authorization: this.apiKimlik.api.getDefaults().headers['Authorization'],
      'devingen-product-id': product._id,
    };
    return (h(Host, { class: "d-block" },
      this.renderHeader(),
      h("kimlik-home", { apiEndpoint: `${services.kimlik}/${services.base}`, apiHeaders: apiHeaders, shownTabs: ['api-keys'], preSelectedTab: 'api-keys', predefinedScopesForAPIKeys: this.generatePredefinedScopes(), allowCustomScopesForAPIKeys: false })));
  }
  static get is() { return "devingen-product-api-keys-page"; }
  static get properties() { return {
    "match": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "MatchResults",
        "resolved": "MatchResults",
        "references": {
          "MatchResults": {
            "location": "import",
            "path": "@stencil/router"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "apiDevingen": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DevingenApi",
        "resolved": "DevingenApi",
        "references": {
          "DevingenApi": {
            "location": "import",
            "path": "../../api/devingen-api"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "apiKimlik": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "KimlikApi",
        "resolved": "KimlikApi",
        "references": {
          "KimlikApi": {
            "location": "import",
            "path": "@dvn/kimlik/api/kimlik-api"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "product": {},
    "error": {},
    "apiKeys": {}
  }; }
}
