'use strict';

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

const index = require('./index-a1121663.js');
require('./index-16c91445.js');
require('./InterceptorHandler-09a1e84b.js');
require('./state-tunnel-786a62ce.js');
const context = require('./context-199a92d5.js');
require('./data-model-f9df493f.js');
const appConfig = require('./app-config-9060e777.js');
require('./BaseField-f50bb8f0.js');
require('./FieldModelGenerator-61c1111e.js');
require('./date-8e8ca89a.js');
require('./index-21b225d5.js');
require('./table-config-d70a1046.js');
require('./string-9e6ebf63.js');
require('./membership-config-79450727.js');
require('./User-ed078a17.js');
const membership = require('./membership-aabb47fb.js');
require('./_commonjsHelpers-206db00d.js');
require('./index-13fb62eb.js');
const route = require('./route-cf47a44e.js');
const index$2 = require('./index-8f577da1.js');
require('./kimlikApi-6a581864.js');
require('./data-transfer-field-025bce2f.js');
require('./filter-52876f3c.js');
const dataApi = require('./dataApi-5225d8e2.js');
const cookie = require('./cookie-8a49bf23.js');
const index$1 = require('./index-6e5eb542.js');
require('./models-5557deb9.js');
require('./index-5df9f17d.js');
require('./ValidatorLength-06e5c6f8.js');
require('./form-view-config-ab8d951a.js');
require('./view-config-1ef57be5.js');
require('./actions-d7eabd95.js');
require('./list-fetch-state-4917b40d.js');
require('./attachment-c2bc9126.js');
require('./instance-fbedf46d.js');
const utils = require('./utils-8a41ac3c.js');
const uye = require('./uye-ad03b095.js');
require('./spaces-ad9dfe8b.js');
require('./detail-view-config-6940447f.js');
require('./index-6923d308.js');
require('./table-list-view-config-0f44c9af.js');
require('./nested-14baa4ef.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 utils.Logger('MentornityConsoleAppContextInjector').setLevel('debug');
    this.logger.infoGroup('componentWillLoad');
    // this.apiAtama = new AtamaApiImpl('', defaultHeaders);
    this.apiData = new dataApi.DataApiImpl(uye.dataApiEndpoint, {
      Authorization: defaultHeaders['Authorization'],
    });
    this.apiKimlik = new uye.KimlikApiMentornity(uye.mentornityApiEndpoint, defaultHeaders);
    this.apiUye = new uye.UyeApiMentornity(uye.mentornityApiEndpoint, defaultHeaders);
  }
  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,
        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$2.injectNotifier(MentornityConsoleAppContextInjector);

exports.mentornity_console_app_context_injector = MentornityConsoleAppContextInjector;
