import { r as registerInstance, h, H as Host } from './index-102043e0.js';
import { i as injectNotifier } from './index-627a1410.js';
import { D as DataApiImpl } from './dataApi-8221972c.js';
import { L as Logger, S as SozlukApi } from './index-1e9f4c53.js';
import { A as AppConfig } from './app-config-d490f9ae.js';
import { M as Membership } from './membership-821de3c5.js';
import { g as getRouteParams } from './route-8be91bee.js';
import { g as getSessionData, i as isUserLoggedIn } from './index-ef2fbee6.js';
import { C as CookieStorage } from './cookie-647f9dc7.js';
import { T as Tunnel } from './context-6bc8f012.js';
import { d as dataApiEndpoint, K as KimlikApiMentornity, m as mentornityApiEndpoint, U as UyeApiMentornity } from './uye-4936a586.js';
import './state-tunnel-04c0b67a.js';
import './kimlikApi-ac700c81.js';
import './data-transfer-field-918730a3.js';
import './BaseField-461b6d0c.js';
import './filter-cbaa3d7d.js';
import './data-model-f5160369.js';
import './membership-config-68ed7772.js';
import './table-config-720f8ea0.js';
import './FieldModelGenerator-ee438a53.js';
import './index-ef734a5e.js';
import './index-336ef773.js';
import './date-ce777316.js';
import './index-0e8b9ea2.js';
import './index-c3eacf05.js';
import './string-3065a411.js';
import './User-d2ee8b71.js';
import './index-d3bd30bd.js';
import './_commonjsHelpers-27f122dd.js';
import './utils-2c1db0af.js';
import './spaces-c4b46e5e.js';
import './table-list-view-config-ff8c1b78.js';
import './index-a1675f50.js';
import './attachment-32decf79.js';
import './InterceptorHandler-6474bcf4.js';
import './view-config-efdeed6d.js';
import './detail-view-config-e2344d5e.js';
import './models-22fcdeab.js';
import './form-view-config-fb04db06.js';
import './ValidatorLength-f56a7c14.js';
import './actions-b9a0f808.js';
import './instance-fe40f49f.js';
import './nested-395a4cd4.js';
import './index-47dfc023.js';
import './list-fetch-state-623a5ba4.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 };
