import { Component, Element, h, Host, Listen, Prop, State } from '@stencil/core';
import * as formViewDomainCreate from '../configs/view-configs/form-view-domain-create';
import * as formViewDomainUpdate from '../configs/view-configs/form-view-domain-update';
import * as formViewDomainMove from '../configs/view-configs/form-view-domain-move';
import * as formViewDomainDelete from '../configs/view-configs/form-view-domain-delete';
import * as tableListViewDomain from '../configs/view-configs/table-list-view-domain';
export class DevingenProductRootDamga {
  constructor() {
    this.isCreateDomainFormShown = false;
    this.isMoveDomainFormShown = false;
    this.isDeleteDomainFormShown = false;
    this.isUpdateDomainFormShown = false;
  }
  onAction(event) {
    const action = event.detail;
    if (action.type === 'navigation') {
      const navigateAction = action;
      if (navigateAction.direction === 'back') {
        // create/update/delete/move domain form closes itself
        this.isCreateDomainFormShown = false;
        this.isUpdateDomainFormShown = false;
        this.isMoveDomainFormShown = false;
        this.isDeleteDomainFormShown = false;
      }
      else if (navigateAction.direction === 'forward') {
        const navigateForwardAction = action;
        if (navigateForwardAction.viewId === formViewDomainCreate.ID) {
          // show create new domain form
          this.isCreateDomainFormShown = true;
        }
        else if (navigateForwardAction.viewId === formViewDomainUpdate.ID) {
          // show create new domain form
          this.isUpdateDomainFormShown = true;
          this.updateDomainFormParams = navigateForwardAction.params;
        }
        else if (navigateForwardAction.viewId === formViewDomainMove.ID) {
          // show move domain form
          this.isMoveDomainFormShown = true;
          this.moveDomainFormParams = navigateForwardAction.params;
        }
        else if (navigateForwardAction.viewId === formViewDomainDelete.ID) {
          // show delete domain form
          this.isDeleteDomainFormShown = true;
          this.deleteDomainFormParams = navigateForwardAction.params;
        }
      }
    }
  }
  onInvalidation(event) {
    var _a;
    (_a = this.el.querySelector(`#${event.detail.targetViewId}`)) === null || _a === void 0 ? void 0 : _a.invalidate(event);
  }
  ;
  render() {
    const { apiDamga, apiData, apiSozluk, isCreateDomainFormShown, isDeleteDomainFormShown, isMoveDomainFormShown, isUpdateDomainFormShown, product, products, updateDomainFormParams, workspaceOwnerships, moveDomainFormParams, deleteDomainFormParams, } = this;
    return (h(Host, { class: "container d-block" },
      h("div", { class: "row justify-content-md-center" },
        h("div", { class: "col-sm-12" },
          h("dvn-app-view-list-view-table", { id: tableListViewDomain.ID, apiData: apiData, apiSozluk: apiSozluk, view: tableListViewDomain.viewConfig(product._id) }),
          isCreateDomainFormShown &&
            h("dvn-dialog", { raw: true, shown: true, onDismiss: () => this.isCreateDomainFormShown = false },
              h("dvn-app-view-form-view", { params: {
                  productId: product._id,
                }, view: formViewDomainCreate.config(apiDamga) })),
          isUpdateDomainFormShown &&
            h("dvn-dialog", { raw: true, shown: true, onDismiss: () => this.isUpdateDomainFormShown = false },
              h("dvn-app-view-form-view", { params: updateDomainFormParams, view: formViewDomainUpdate.config(apiDamga) })),
          isMoveDomainFormShown &&
            h("dvn-dialog", { raw: true, shown: true, onDismiss: () => this.isMoveDomainFormShown = false },
              h("dvn-app-view-form-view", { params: moveDomainFormParams, view: formViewDomainMove.config(apiDamga, products, workspaceOwnerships) })),
          isDeleteDomainFormShown &&
            h("dvn-dialog", { raw: true, shown: true, onDismiss: () => this.isDeleteDomainFormShown = false },
              h("dvn-app-view-form-view", { params: deleteDomainFormParams, view: formViewDomainDelete.config(apiDamga) }))))));
  }
  static get is() { return "devingen-product-damga-domains"; }
  static get encapsulation() { return "scoped"; }
  static get properties() { return {
    "apiDamga": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DamgaApi",
        "resolved": "DamgaApi",
        "references": {
          "DamgaApi": {
            "location": "import",
            "path": "../api/damga-api"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "apiData": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "DataApi",
        "resolved": "DataApi",
        "references": {
          "DataApi": {
            "location": "import",
            "path": "@dvn/core/api"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "apiSozluk": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "SozlukApi",
        "resolved": "SozlukApi",
        "references": {
          "SozlukApi": {
            "location": "import",
            "path": "@dvn/sozluk/api"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "product": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Product",
        "resolved": "Product",
        "references": {
          "Product": {
            "location": "import",
            "path": "../../../models/product"
          }
        }
      },
      "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 {
    "isCreateDomainFormShown": {},
    "isMoveDomainFormShown": {},
    "isDeleteDomainFormShown": {},
    "isUpdateDomainFormShown": {},
    "updateDomainFormParams": {},
    "deleteDomainFormParams": {},
    "moveDomainFormParams": {}
  }; }
  static get elementRef() { return "el"; }
  static get listeners() { return [{
      "name": "action",
      "method": "onAction",
      "target": undefined,
      "capture": false,
      "passive": false
    }, {
      "name": "invalidation",
      "method": "onInvalidation",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
