'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-1141a245.js');
const takvimAvailableTimePickerViewConfig = require('./takvim-available-time-picker-view-config-816b6faf.js');
const tableConfig = require('./table-config-8b14c7d3.js');
const viewConfig = require('./view-config-7972654b.js');
const mentorintyBridgeApi = require('./mentorinty-bridge-api-0534712d.js');
const session = require('./session-b6f20e12.js');
require('./FieldModelGenerator-1900d81a.js');
require('./reference-field-1239b0c3.js');
require('./BaseField-381327a9.js');
require('./index-2eea69a0.js');
require('./FieldGenerator-279a646b.js');
require('./date-a24d7714.js');
require('./index-0783d14f.js');
require('./index-e8e4d80b.js');
require('./index-9d3d3d15.js');
require('./index-9fd84b93.js');
require('./index-61f9621a.js');
require('./data-model-9afb7f54.js');
require('./apiBase-e4ebaf8b.js');
require('./data-transfer-field-e8417d5f.js');
require('./filter-d5040f65.js');
require('./index-e751cab0.js');
require('./attachment-b0acc4c1.js');
require('./membership-ed8d3277.js');
require('./string-de672b69.js');
require('./User-e889279b.js');
require('./CalendarConfig-ee7bb722.js');
require('./UserSettings-fc04eb54.js');
require('./cookie-135bf612.js');
require('./kimlik-api-d3c479a3.js');
require('./_commonjsHelpers-206db00d.js');
require('./index-33e96540.js');
require('./instance-36d7564f.js');
require('./index-a2e99c85.js');
require('./i18n-49870fc9.js');
require('./i18n-5585a319.js');
require('./calendar-e4b7baeb.js');
require('./index-b776fc14.js');
require('./moment-7a3433f2.js');

class TakvimDailyCalendarViewConfig extends viewConfig.DvnAppViewConfig {
  static decode(json) {
    const model = Object.assign(Object.create(TakvimDailyCalendarViewConfig.prototype), json);
    model.table = tableConfig.TableConfig.decode(model.table);
    return model;
  }
}

const MentornityHomeMessageWrapper = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
  }
  componentWillLoad() {
    // fetch the context async to unblock the component render
    session.generateMentornitySessionContext(this.contextParams, { fetchConfig: true })
      .then((mentornitySessionContext) => {
      this.mentornitySessionContext = mentornitySessionContext;
      this.view = generateView(mentornitySessionContext);
      this.membership = session.generateMembershipForRole('admin');
    })
      .catch(error => this.error = error);
  }
  onViewMeeting(event) {
    window.dispatchEvent(new CustomEvent('dvn.mentornity-admin-calendar-view.open-meeting-page', {
      detail: {
        meetingId: event.detail._id,
      }
    }));
  }
  onAction(event) {
    const action = event.detail;
    switch (action.name) {
      case 'open-meeting-detail-after-creation':
        // dispatch event for Mentornity web-client to handle the action
        window.dispatchEvent(new CustomEvent('dvn.mentornity-admin-calendar-view.open-meeting-page', {
          detail: {
            meetingId: action.params.meetingId,
          }
        }));
        break;
    }
  }
  render() {
    const { error, mentornitySessionContext, view } = this;
    if (!!error) {
      return (index.h("dvn-card", { leanedSides: true, tint: "danger" }, "Failed to get data."));
    }
    if (!mentornitySessionContext) {
      return (index.h("div", { class: "d-flex justify-content-center pt-3" }, index.h("dvn-progress", { indefinite: true })));
    }
    return (index.h(index.Host, { class: "d-flex flex-grow-1", style: { overflow: 'hidden', background: 'var(--color-background-primary)' } }, index.h("mentornity-root-wrapper", null, index.h("dvn-app-view-takvim-daily-calendar-view", { apiData: this.mentornitySessionContext.mentornityBridgeApi, apiSozluk: this.mentornitySessionContext.apiSozluk, apiTakvim: this.mentornitySessionContext.mentornityBridgeApi, user: this.mentornitySessionContext.user, userSettings: this.mentornitySessionContext.userSettings, membership: this.membership, view: view }))));
  }
};
function generateView(mentornitySessionContext) {
  // this value can be changed to 'mentees' or 'groups' to show them in the list on the left
  const membershipConfigIdToGroupMeetings = 'mentors';
  let membershipConfigIdToViewOnMeetings = 'mentees';
  if (mentornitySessionContext.organisationConfig.menteeType === 'group') {
    membershipConfigIdToViewOnMeetings = 'groups';
  }
  return TakvimDailyCalendarViewConfig.decode({
    i18nEntryId: 'dailyCalendarView',
    table: mentorintyBridgeApi.generateCalendarConfig(mentornitySessionContext.organisationConfig),
    membershipConfigIdToGroupMeetings,
    membershipConfigIdToViewOnMeetings,
    availableTimePickerConfig: takvimAvailableTimePickerViewConfig.TakvimAvailableTimePickerViewConfig.decode({
      _id: 'admin-calendar-page-available-time-picker-view-wrapper',
      i18nEntryId: 'user-card-list-page-available-time-picker-view',
      table: mentorintyBridgeApi.generateCalendarConfig(mentornitySessionContext.organisationConfig),
      successNavigationAction: {
        type: 'navigation',
        direction: 'forward',
        name: 'open-meeting-detail-after-creation',
        params: {
          conversionConfig: {
            'item._id': 'meetingId',
          }
        }
      },
    }),
  });
}

exports.mentornity_admin_calendar_view = MentornityHomeMessageWrapper;
