import { r as registerInstance, h, H as Host } from './index-55faf181.js';
import { i as injectNotifier } from './index-7884b902.js';
import { D as DataApiImpl } from './dataApi-abfa358d.js';
import { L as Logger } from './utils-ee3626ab.js';
import { A as AppConfig } from './app-config-d490f9ae.js';
import { M as Membership } from './membership-61c4a2f7.js';
import { g as getRouteParams } from './route-8be91bee.js';
import { g as getSessionData, i as isUserLoggedIn } from './index-36f6c00a.js';
import { C as CookieStorage } from './cookie-93ea205f.js';
import { T as Tunnel } from './context-8273b228.js';
import { d as dataApiEndpoint, K as KimlikApiMentornity, m as mentornityApiEndpoint, U as UyeApiMentornity } from './uye-1d41612a.js';
import './state-tunnel-04c0b67a.js';
import './kimlikApi-7350588e.js';
import './data-transfer-field-918730a3.js';
import './BaseField-461b6d0c.js';
import './filter-cbaa3d7d.js';
import './data-model-f5160369.js';
import './membership-config-a51a5232.js';
import './table-config-5c917348.js';
import './FieldModelGenerator-1ee7fda2.js';
import './index-6a1cf9c1.js';
import './index-403e215e.js';
import './date-ce777316.js';
import './index-083a6906.js';
import './index-fa1db470.js';
import './string-3065a411.js';
import './User-d2ee8b71.js';
import './index-d3bd30bd.js';
import './_commonjsHelpers-27f122dd.js';
import './spaces-460b4232.js';
import './table-list-view-config-8e775e94.js';
import './index-ebde6a66.js';
import './attachment-32decf79.js';
import './InterceptorHandler-6474bcf4.js';
import './view-config-39fd369a.js';
import './detail-view-config-dafcc086.js';
import './models-22fcdeab.js';
import './form-view-config-00abddd1.js';
import './ValidatorLength-f56a7c14.js';
import './actions-b9a0f808.js';
import './instance-46ab1e99.js';
import './list-fetch-state-623a5ba4.js';
import './index-da37d89d.js';
import './nested-395a4cd4.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);
  }
  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 };
