import { r as registerInstance, h, H as Host } from './index-b6f10a81.js';
import './index-ec7dc2ad.js';
import './InterceptorHandler-6474bcf4.js';
import './state-tunnel-04c0b67a.js';
import { T as Tunnel } from './context-bb68e904.js';
import './data-model-bb5789f5.js';
import { A as AppConfig } from './app-config-cf28072f.js';
import './BaseField-d94c5b14.js';
import './FieldModelGenerator-6ec60042.js';
import './date-b270be76.js';
import './index-94c1d7bf.js';
import './table-config-c0c15e50.js';
import './string-2d991277.js';
import './membership-config-856f6e58.js';
import './User-e14f1ece.js';
import { M as Membership } from './membership-093c8342.js';
import './_commonjsHelpers-63c253cd.js';
import './index-fd2b14ae.js';
import { g as getRouteParams } from './route-ac9f3a5e.js';
import { i as injectNotifier } from './index-213e8cee.js';
import './kimlikApi-81acfec6.js';
import './data-transfer-field-1ad95e08.js';
import './filter-cbaa3d7d.js';
import { D as DataApiImpl } from './dataApi-95bebee9.js';
import { C as CookieStorage } from './cookie-d9098150.js';
import { g as getSessionData, i as isUserLoggedIn } from './index-3a5c6fef.js';
import './models-ccfd4f3c.js';
import './index-44e741ab.js';
import './ValidatorLength-f56a7c14.js';
import './form-view-config-bb777190.js';
import './view-config-3ab16b28.js';
import './actions-b9a0f808.js';
import './list-fetch-state-8615484c.js';
import './attachment-8831acff.js';
import './instance-f50cdfd9.js';
import { L as Logger } from './utils-9344a2af.js';
import { d as dataApiEndpoint, K as KimlikApiMentornity, m as mentornityApiEndpoint, U as UyeApiMentornity } from './uye-f57c7c20.js';
import './spaces-ba2f2c63.js';
import './detail-view-config-6178fa2c.js';
import './index-47482faa.js';
import './table-list-view-config-80e66dd9.js';
import './nested-15d95467.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);
  }
  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,
        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 };
