import { Component, h, Listen, Prop, State } from '@stencil/core';
import { generateMentornitySessionContext } from "../../util/session";
import { TakvimMeetingListViewConfig } from "@dvn/takvim/views/dvn-app-view-takvim-meeting-list-view-table/takvim-meeting-list-view-config";
import { generateCalendarConfig } from "../../api/mentorinty-bridge-api";
export class MentornityMyMeetingsWrapper {
  componentWillLoad() {
    // fetch the context async to unblock the component render
    generateMentornitySessionContext(this.contextParams, { fetchConfig: true })
      .then((mentornitySessionContext) => {
      this.mentornitySessionContext = mentornitySessionContext;
      this.view = TakvimMeetingListViewConfig.decode({
        _id: 'my-meetings-page-meeting-list-view',
        i18nEntryId: 'my-meetings-page-meeting-list-view',
        table: generateCalendarConfig(this.mentornitySessionContext.organisationConfig),
      });
    })
      .catch(error => {
      console.log(error);
      this.error = error;
    });
  }
  onAction(event) {
    const action = event.detail;
    switch (action.name) {
      case 'open-meeting-detail-from-meeting-list':
        window.dispatchEvent(new CustomEvent('dvn.mentornity-my-meetings-wrapper.open-meeting-detail', {
          detail: {
            meetingId: action.params.meetingId,
          }
        }));
        break;
    }
  }
  render() {
    const { error, mentornitySessionContext, view } = this;
    if (!!error) {
      return (h("dvn-card", { leanedSides: true, tint: "danger" }, "Failed to get data."));
    }
    if (!mentornitySessionContext) {
      return (h("div", { class: "d-flex flex-grow-1 justify-content-center pt-3" },
        h("dvn-progress", { indefinite: true })));
    }
    const { apiSozluk, mentornityBridgeApi, user, userSettings } = mentornitySessionContext;
    return (h("dvn-app-view-takvim-meeting-list-view-table", { apiSozluk: apiSozluk, apiTakvim: mentornityBridgeApi, userSettings: userSettings, view: view, params: {
        guest1Id: user._id
      }, scrollToFitHeight: true }));
  }
  static get is() { return "mentornity-my-meetings-wrapper"; }
  static get originalStyleUrls() { return {
    "$": ["./mentornity-my-meetings-wrapper.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["mentornity-my-meetings-wrapper.css"]
  }; }
  static get properties() { return {
    "contextParams": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "MentornityContextParams",
        "resolved": "MentornityContextParams",
        "references": {
          "MentornityContextParams": {
            "location": "import",
            "path": "../../util/session"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "error": {},
    "view": {},
    "mentornitySessionContext": {}
  }; }
  static get listeners() { return [{
      "name": "action",
      "method": "onAction",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
