'use strict';

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

const index = require('./index-ce58ddc5.js');
const index$3 = require('./index-407b6960.js');
const dataApi = require('./dataApi-fbe22059.js');
const index$2 = require('./index-b2910095.js');
const appConfig = require('./app-config-cb7e78a4.js');
const membership = require('./membership-310dd68e.js');
const route = require('./route-d107e176.js');
const index$1 = require('./index-4b96acc9.js');
const cookie = require('./cookie-ea977378.js');
const context = require('./context-831858ba.js');
const uye = require('./uye-39bd9aa4.js');
const env = require('./env-83ebcbc7.js');
require('./state-tunnel-786a62ce.js');
require('./apiBase-b14a8285.js');
require('./data-transfer-field-0ce05c1a.js');
require('./BaseField-d019ade6.js');
require('./filter-d5040f65.js');
require('./data-model-9afb7f54.js');
require('./table-config-73a193be.js');
require('./FieldModelGenerator-1af8e5c3.js');
require('./reference-field-dda66f2e.js');
require('./index-f92537c9.js');
require('./index-7e3bc620.js');
require('./date-25b104f6.js');
require('./index-9ea6c7b1.js');
require('./index-93271b8c.js');
require('./index-29b7cb16.js');
require('./index-792d710c.js');
require('./string-de672b69.js');
require('./User-e15e0b6d.js');
require('./index-33e96540.js');
require('./_commonjsHelpers-206db00d.js');
require('./kimlikApi-f4f62100.js');
require('./utils-ac361312.js');
require('./spaces-4a775c20.js');
require('./ValidatorRegex-f7d85270.js');
require('./InterceptorHandler-09a1e84b.js');
require('./detail-view-config-ba51db6c.js');
require('./view-config-1c8cc7cb.js');
require('./index-fa185e3b.js');
require('./attachment-3090e25e.js');
require('./models-19fd9c92.js');
require('./ModifierTrimmer-1463d100.js');
require('./ValidatorLength-06e5c6f8.js');
require('./form-view-config-b408970d.js');
require('./actions-d7eabd95.js');
require('./instance-fba77445.js');
require('./nested-8980065f.js');
require('./index-c2c40444.js');
require('./list-fetch-state-a9e880b1.js');
require('./ValidatorEmail-4449f08a.js');
require('./table-list-view-config-f6ec7162.js');
require('./DvnDataAdapter-8f89f436.js');
require('./time-zones-5b212929.js');

let 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;
