'use strict';

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

const index = require('./index-1141a245.js');
const index$3 = require('./index-f41ad23a.js');
const dataApi = require('./dataApi-f2405711.js');
const index$2 = require('./index-a2e99c85.js');
const appConfig = require('./app-config-cb7e78a4.js');
const membership = require('./membership-ed8d3277.js');
const route = require('./route-d107e176.js');
const index$1 = require('./index-c7be53b8.js');
const cookie = require('./cookie-135bf612.js');
const context = require('./context-d32abf1f.js');
const uye = require('./uye-43a67ce8.js');
const env = require('./env-fcda6e03.js');
require('./state-tunnel-786a62ce.js');
require('./apiBase-e4ebaf8b.js');
require('./data-transfer-field-e8417d5f.js');
require('./BaseField-381327a9.js');
require('./filter-d5040f65.js');
require('./data-model-9afb7f54.js');
require('./table-config-8b14c7d3.js');
require('./FieldModelGenerator-1900d81a.js');
require('./reference-field-1239b0c3.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('./string-de672b69.js');
require('./User-e889279b.js');
require('./index-33e96540.js');
require('./_commonjsHelpers-206db00d.js');
require('./kimlik-api-d3c479a3.js');
require('./utils-f5bf4fbb.js');
require('./spaces-560c9786.js');
require('./raw-data-34f1739c.js');
require('./detail-view-config-4fe32db3.js');
require('./view-config-7972654b.js');
require('./index-e751cab0.js');
require('./attachment-b0acc4c1.js');
require('./models-8b357ee7.js');
require('./InterceptorHandler-09a1e84b.js');
require('./ModifierTrimmer-1463d100.js');
require('./ValidatorLength-06e5c6f8.js');
require('./ValidatorRegex-2120bfb5.js');
require('./form-view-config-36569bb4.js');
require('./actions-d7eabd95.js');
require('./instance-36d7564f.js');
require('./nested-d75d7d5f.js');
require('./index-e99b474f.js');
require('./list-fetch-state-a9e880b1.js');
require('./ValidatorEmail-4449f08a.js');
require('./table-list-view-config-5eaa0344.js');
require('./DvnDataAdapter-8f89f436.js');
require('./DvnDataProvider-6f26d1f7.js');
require('./time-zones-5b212929.js');

const MentornityConsoleAppContextInjector = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
  }
  componentWillLoad() {
    const defaultHeaders = {
      'Session-Token': 'NTdiMzY3NjBlNjNiY2UxZWViMDAwMDA0',
    };
    if (index$1.getSessionData().token) {
      defaultHeaders['Authorization'] = `Bearer ${index$1.getSessionData().token}`;
    }
    this.storage = new cookie.CookieStorage();
    this.logger = new index$2.Logger('MentornityConsoleAppContextInjector').setLevel('debug');
    this.logger.infoGroup('componentWillLoad');
    // this.apiAtama = new AtamaApiImpl('', defaultHeaders);
    this.apiData = new dataApi.DataApiImpl(env.dataApiEndpoint, {
      Authorization: defaultHeaders['Authorization'],
    });
    this.apiKimlik = new uye.KimlikApiMentornity(env.mentornityApiEndpoint, defaultHeaders);
    this.apiUye = new uye.UyeApiMentornity(env.mentornityApiEndpoint, defaultHeaders);
    this.apiSozluk = new index$2.SozlukApi();
  }
  componentDidLoad() {
    if (!index$1.isUserLoggedIn()) {
      // this injector is also used for anonymous routes
      return;
    }
    const { membershipId } = route.getRouteParams(location.pathname);
    const getApp = (mid) => this.apiUye.getAppConfigOfMembership(mid).then(response => {
      this.appConfig = appConfig.AppConfig.decode(response);
    });
    this.apiKimlik.getSession().then(response => {
      this.user = response.user;
      this.apiUye.getMembershipsOfUser(response.user._id).then(response => {
        const memberships = response.results;
        this.memberships = memberships;
        if (!memberships || memberships.length === 0) {
          return;
        }
        if (membershipId) {
          this.membership = memberships.find(m => m._id === membershipId);
          getApp(this.membership.config._id);
          return;
        }
        this.membership = membership.Membership.decode(memberships[0]);
        getApp(memberships[0].config._id);
      });
    });
  }
  invalidateAppContext() {
    this.logger.debug('invalidateAppContext');
  }
  render() {
    return (index.h(index.Host, null, index.h(context.Tunnel.Provider, { state: {
        apiAtama: this.apiAtama,
        apiData: this.apiData,
        apiKimlik: this.apiKimlik,
        apiUye: this.apiUye,
        apiSozluk: this.apiSozluk,
        logger: this.logger,
        storage: this.storage,
        appContextInvalidator: () => this.invalidateAppContext(),
        appConfig: this.appConfig,
        membership: this.membership,
        memberships: this.memberships,
        notifier: this.notifier,
        user: this.user,
        theme: this.theme,
      } }, index.h("slot", null))));
  }
};
index$3.injectNotifier(MentornityConsoleAppContextInjector);

exports.mentornity_console_app_context_injector = MentornityConsoleAppContextInjector;
