import { injectNotifier } from '@dvn/alaca/global/notifier';
import { Component, h, Host, Listen, Prop, State } from '@stencil/core';
import * as formViewProductCreate from '../../configs/view-configs/form-view-products-create';
import * as formViewWorkspaceCreate from '../../configs/view-configs/form-view-workspace-create';
export class DevingenHomePage {
  constructor() {
    this.isCreateWorkspaceFormShown = false;
    this.isCreateProductFormShown = false;
  }
  onInvalidation(_event) {
    // new workspace or product is created
    this.isCreateWorkspaceFormShown = false;
    this.isCreateProductFormShown = false;
  }
  ;
  componentWillLoad() {
  }
  render() {
    const { isCreateProductFormShown, isCreateWorkspaceFormShown, products, selectedWorkspaceToCreateProduct, workspaceOwnerships } = this;
    if (!workspaceOwnerships || !products) {
      return (h("div", { class: "d-flex justify-content-center pt-3" },
        h("dvn-progress", { indefinite: true })));
    }
    return (h(Host, null,
      h("div", { class: "container" },
        h("div", { class: "row" }, workspaceOwnerships.map(workspaceOwnership => {
          const { workspace } = workspaceOwnership;
          return (h("div", { class: "col-sm-12" },
            h("h2", { class: "mt-3" }, workspace.name),
            h("div", { class: "row" },
              products.filter(product => product.workspace._id === workspace._id).map(product => (h("div", { class: "col-sm-12 col-md-4 mb-3" },
                h("stencil-route-link", { url: `/products/${product._id}` },
                  h("dvn-card", { bodyLeaned: true, elevation: 0, leaned: true, selectable: true, tint: "primary" },
                    h("devingen-product-card", { product: product })))))),
              h("div", { class: "col-sm-12 col-md-4" },
                h("dvn-card", { bodyLeaned: true, elevation: 0, leaned: true, selectable: true, tint: "primary" },
                  h("devingen-product-card", { onClick: () => {
                      this.isCreateProductFormShown = true;
                      this.selectedWorkspaceToCreateProduct = workspace._id;
                    } }))))));
        })),
        h("div", { class: "row" },
          h("div", { class: "col-sm-12 col-md-4 mt-3 pt-3" },
            h("dvn-button", { leaned: true, onClick: () => this.isCreateWorkspaceFormShown = true, view: "flat" },
              h("dvn-icon", { iconName: `uil uil-plus` }),
              "Add new workspace")))),
      isCreateWorkspaceFormShown &&
        h("dvn-dialog", { raw: true, shown: true, onDismiss: () => this.isCreateWorkspaceFormShown = false },
          h("dvn-app-view-form-view", { view: formViewWorkspaceCreate.config(this.apiDevingen) })),
      isCreateProductFormShown &&
        h("dvn-dialog", { raw: true, shown: true, onDismiss: () => this.isCreateProductFormShown = false },
          h("dvn-app-view-form-view", { view: formViewProductCreate.config(this.apiDevingen), params: {
              workspaceId: selectedWorkspaceToCreateProduct,
              type: 'damga',
            } }))));
  }
  static get is() { return "devingen-home-page"; }
  static get properties() { return {
    "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/kimlikApi"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "notifier": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Notifier",
        "resolved": "Notifier",
        "references": {
          "Notifier": {
            "location": "import",
            "path": "@dvn/alaca/global/notifier/models"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "products": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Product[]",
        "resolved": "Product[]",
        "references": {
          "Product": {
            "location": "import",
            "path": "../../models/product"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "workspaceOwnerships": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "WorkspaceOwnership[]",
        "resolved": "WorkspaceOwnership[]",
        "references": {
          "WorkspaceOwnership": {
            "location": "import",
            "path": "../../models/workspace-ownership"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "isCreateWorkspaceFormShown": {},
    "isCreateProductFormShown": {},
    "selectedWorkspaceToCreateProduct": {}
  }; }
  static get listeners() { return [{
      "name": "invalidation",
      "method": "onInvalidation",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
injectNotifier(DevingenHomePage);
