import { r as registerInstance, h, H as Host } from './index-b7735e0d.js';
import { i as injectNotifier } from './index-94b34cb1.js';
import { D as DataApiImpl } from './dataApi-82558134.js';
import { L as Logger, S as SozlukApi } from './index-1e9f4c53.js';
import { A as AppConfig } from './app-config-5d14e7bf.js';
import { M as Membership } from './membership-e92743d1.js';
import { g as getRouteParams } from './route-8be91bee.js';
import { g as getSessionData, i as isUserLoggedIn } from './index-c7307038.js';
import { C as CookieStorage } from './cookie-1686830b.js';
import { T as Tunnel } from './context-ced8e86d.js';
import { K as KimlikApiMentornity, U as UyeApiMentornity } from './uye-e958de1c.js';
import { d as dataApiEndpoint, m as mentornityApiEndpoint } from './env-52322014.js';
import './state-tunnel-04c0b67a.js';
import './apiBase-d573f009.js';
import './data-transfer-field-918730a3.js';
import './BaseField-461b6d0c.js';
import './filter-cbaa3d7d.js';
import './data-model-f7ccf826.js';
import './table-config-0c06fb1f.js';
import './FieldModelGenerator-020f4a04.js';
import './reference-field-0e7cd534.js';
import './index-7b119e61.js';
import './index-403101cb.js';
import './date-ce777316.js';
import './index-1d3efe49.js';
import './index-eb14fd2d.js';
import './index-80ec23ef.js';
import './index-4c39b6a6.js';
import './string-3065a411.js';
import './User-1ef5a482.js';
import './index-d3bd30bd.js';
import './_commonjsHelpers-27f122dd.js';
import './kimlikApi-0d7e6ce7.js';
import './utils-00b62373.js';
import './spaces-9bcb3731.js';
import './ValidatorRegex-20b5a564.js';
import './InterceptorHandler-6474bcf4.js';
import './detail-view-config-59c98d8d.js';
import './view-config-dfb61752.js';
import './index-774783ee.js';
import './attachment-32decf79.js';
import './models-22fcdeab.js';
import './ModifierTrimmer-2f77f917.js';
import './ValidatorLength-f56a7c14.js';
import './form-view-config-16052dc8.js';
import './actions-b9a0f808.js';
import './instance-7b02ef1d.js';
import './nested-395a4cd4.js';
import './index-a1075948.js';
import './list-fetch-state-d8c2f8ef.js';
import './ValidatorEmail-df7a1b77.js';
import './table-list-view-config-99e5c0fd.js';
import './DvnDataAdapter-536a3258.js';
import './time-zones-cf1e6113.js';

let MentornityConsoleAppContextInjector = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  componentWillLoad() {
    const defaultHeaders = {
      'Session-Token': 'NTdiMzY3NjBlNjNiY2UxZWViMDAwMDA0',
    };
    if (getSessionData().token) {
      defaultHeaders['Authorization'] = `Bearer ${getSessionData().token}`;
    }
    this.storage = new CookieStorage();
    this.logger = new Logger('MentornityConsoleAppContextInjector').setLevel('debug');
    this.logger.infoGroup('componentWillLoad');
    // this.apiAtama = new AtamaApiImpl('', defaultHeaders);
    this.apiData = new DataApiImpl(dataApiEndpoint, {
      Authorization: defaultHeaders['Authorization'],
    });
    this.apiKimlik = new KimlikApiMentornity(mentornityApiEndpoint, defaultHeaders);
    this.apiUye = new UyeApiMentornity(mentornityApiEndpoint, defaultHeaders);
    this.apiSozluk = new SozlukApi();
  }
  componentDidLoad() {
    if (!isUserLoggedIn()) {
      // this injector is also used for anonymous routes
      return;
    }
    const { membershipId } = getRouteParams(location.pathname);
    const getApp = (mid) => this.apiUye.getAppConfigOfMembership(mid).then(response => {
      this.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.decode(memberships[0]);
        getApp(memberships[0].config._id);
      });
    });
  }
  invalidateAppContext() {
    this.logger.debug('invalidateAppContext');
  }
  render() {
    return (h(Host, null, h(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,
      } }, h("slot", null))));
  }
};
injectNotifier(MentornityConsoleAppContextInjector);

export { MentornityConsoleAppContextInjector as mentornity_console_app_context_injector };
