'use strict';

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

const index = require('./index-36b3af04.js');
const index$2 = require('./index-4d2f1ab7.js');
const dataApi = require('./dataApi-4fa79a50.js');
const utils = require('./utils-d768590e.js');
const appConfig = require('./app-config-e62f5843.js');
const membership = require('./membership-dfbf512e.js');
const route = require('./route-d107e176.js');
const index$1 = require('./index-2efe9739.js');
const cookie = require('./cookie-370bc992.js');
const context = require('./context-68eec200.js');
const uye = require('./uye-12faf60b.js');
require('./state-tunnel-786a62ce.js');
require('./kimlikApi-85c6d3ac.js');
require('./data-transfer-field-0ce05c1a.js');
require('./BaseField-d019ade6.js');
require('./filter-d5040f65.js');
require('./data-model-c51de090.js');
require('./membership-config-707b2c51.js');
require('./table-config-444a77e4.js');
require('./FieldModelGenerator-205dd99c.js');
require('./index-74a00556.js');
require('./index-a8f1783c.js');
require('./date-25b104f6.js');
require('./index-fe19a98b.js');
require('./index-ae305bae.js');
require('./string-de672b69.js');
require('./User-286a0714.js');
require('./index-33e96540.js');
require('./_commonjsHelpers-206db00d.js');
require('./spaces-2fa9fa10.js');
require('./table-list-view-config-298c7662.js');
require('./index-d90390f1.js');
require('./attachment-3090e25e.js');
require('./InterceptorHandler-09a1e84b.js');
require('./view-config-ec5f62df.js');
require('./detail-view-config-594cc3b7.js');
require('./models-19fd9c92.js');
require('./form-view-config-51279874.js');
require('./ValidatorLength-06e5c6f8.js');
require('./actions-d7eabd95.js');
require('./instance-79d61640.js');
require('./list-fetch-state-7befe791.js');
require('./index-0cd3bcc0.js');
require('./nested-8980065f.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 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;
