import { r as registerInstance, h, H as Host } from './index-ecdfb761.js';
import { i as injectNotifier } from './index-1e6a7311.js';
import { D as DataApiImpl } from './dataApi-c77b0bad.js';
import { L as Logger, S as SozlukApi } from './index-3bf9b308.js';
import { A as AppConfig } from './app-config-5d14e7bf.js';
import { M as Membership } from './membership-24db029a.js';
import { g as getRouteParams } from './route-8be91bee.js';
import { g as getSessionData, i as isUserLoggedIn } from './index-7d83a942.js';
import { C as CookieStorage } from './cookie-9f22e0fb.js';
import { T as Tunnel } from './context-c50e1599.js';
import { K as KimlikApiMentornity, U as UyeApiMentornity } from './uye-15e20df0.js';
import { d as dataApiEndpoint, m as mentornityApiEndpoint } from './env-bd518340.js';
import './state-tunnel-04c0b67a.js';
import './apiBase-648a161d.js';
import './data-transfer-field-2f305919.js';
import './BaseField-0b01dc2c.js';
import './filter-cbaa3d7d.js';
import './data-model-f7ccf826.js';
import './table-config-3820fb34.js';
import './FieldModelGenerator-03c7516c.js';
import './reference-field-a5b414d1.js';
import './index-61dcd269.js';
import './FieldGenerator-3ae403b2.js';
import './date-1bc489bd.js';
import './index-4e451db4.js';
import './index-32d8b974.js';
import './index-23baeeef.js';
import './index-09efdc01.js';
import './index-150b6a59.js';
import './string-3065a411.js';
import './User-9f1f4513.js';
import './index-d3bd30bd.js';
import './_commonjsHelpers-27f122dd.js';
import './kimlik-api-66e341bd.js';
import './utils-7adf28a3.js';
import './spaces-a5a0cc70.js';
import './raw-data-eb55820e.js';
import './detail-view-config-47244869.js';
import './view-config-2fc2ba10.js';
import './index-5f14b4fc.js';
import './attachment-d13ad547.js';
import './models-3a85e626.js';
import './InterceptorHandler-6474bcf4.js';
import './ModifierTrimmer-2f77f917.js';
import './ValidatorLength-f56a7c14.js';
import './ValidatorRegex-8645386d.js';
import './form-view-config-db7fef80.js';
import './actions-b9a0f808.js';
import './instance-db63ecb7.js';
import './nested-457f7ba9.js';
import './index-8bcd148f.js';
import './list-fetch-state-d8c2f8ef.js';
import './ValidatorEmail-df7a1b77.js';
import './table-list-view-config-b2e4402c.js';
import './DvnDataAdapter-536a3258.js';
import './DvnDataProvider-86fd3a3b.js';
import './time-zones-cf1e6113.js';

const 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 };
