'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-1141a245.js');
const dark = require('./dark-f2d90718.js');
const dataApi = require('./dataApi-27259c95.js');
const kimlikApi = require('./kimlik-api-663f4884.js');
const index$1 = require('./index-36cc8bab.js');
const cookie = require('./cookie-e64bc800.js');
const apiBase = require('./apiBase-6c66ff1b.js');
const services = require('./services-9cb6ea3a.js');
const light = require('./light-d6947636.js');
require('./colors-a0e2d25f.js');
require('./data-transfer-field-e8417d5f.js');
require('./BaseField-381327a9.js');
require('./filter-d5040f65.js');
require('./_commonjsHelpers-206db00d.js');

class DevingenApi {
  constructor(endpoint, defaultHeaders = {}) {
    // region products
    this.createProduct = (body) => this.api.post(`products`, body);
    this.getProducts = (query = {}) => this.api.get('products', query);
    this.getProduct = (id) => this.api.get(`products/${id}`);
    this.updateProduct = (id, body) => this.api.put(`products/${id}`, body);
    this.deleteProduct = (id) => this.api.delete(`products/${id}`);
    // endregion
    // region workspace
    this.createWorkspace = (name) => this.api.post(`workspaces`, { name });
    this.updateWorkspace = (id, body) => this.api.put(`workspaces/${id}`, body);
    this.deleteWorkspace = (id) => this.api.delete(`workspaces/${id}`);
    // endregion
    this.getWorkspaceOwnerships = () => this.api.get('workspace-ownerships');
    // region product-settings-kimlik
    this.createProductSettingsKimlik = (productId, databaseProductId, webhookAddress, headers) => this.api.post(`product-settings-kimlik`, { product: { _id: productId }, databaseProduct: { _id: databaseProductId }, webhookAddress, headers });
    this.findProductSettingsKimlik = (productId) => this.api.get(`product-settings-kimlik`, { productId });
    // endregion
    // region product-settings-taban
    this.createProductSettingsTaban = (productId) => this.api.post(`product-settings-taban`, { product: { _id: productId } });
    this.findProductSettingsTaban = (productId) => this.api.get(`product-settings-taban`, { productId });
    this.api = new apiBase.APIBase(endpoint, defaultHeaders);
  }
}

/**
 * Returns the current appearance, starts listening to the appearance change events and notifies the callback.
 *
 * @param callback
 */
function watchDeviceAppearance(callback) {
  window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (event) => {
    callback(event.matches ? 'dark' : 'light');
  });
  if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
    return 'dark';
  }
  return 'light';
}

const wrapContent = (theme, content) => (index.h(index.Host, null, index.h("dvn-theme-provider", { theme: theme, colorBackground: true, fitHeight: true }, index.h("dvn-global-table", null), index.h("dvn-global-grid", null), index.h("dvn-global-text", null), index.h("notifier-wrapper", null, content))));
const DevingenRoot = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.theme = light.light;
  }
  componentWillLoad() {
    // get the current appearance from device and start watching the appearance change events
    if (watchDeviceAppearance(appearance => this.theme = appearance === 'dark' ? dark.dark : light.light) === 'dark') {
      this.theme = dark.dark;
    }
  }
  render() {
    const { theme } = this;
    const jwt = new cookie.CookieStorage().getAll().jwt;
    const headers = {
      Authorization: jwt ? `Bearer ${new cookie.CookieStorage().getAll().jwt}` : undefined,
    };
    const apiKimlik = new kimlikApi.KimlikApiImpl(`${services.prod.kimlik}/${services.prod.base}`, headers);
    const apiData = new dataApi.DataApiImpl(`${services.prod.data}/${services.prod.base}`, headers);
    const apiDevingen = new DevingenApi(services.prod.devingen, headers);
    if (!index$1.isUserLoggedIn()) {
      return wrapContent(theme, index.h("devingen-login-page", { apiKimlik: apiKimlik }));
    }
    return wrapContent(theme, index.h("devingen-router", { apiKimlik: apiKimlik, apiDevingen: apiDevingen, apiData: apiData }));
  }
};

exports.devingen_root = DevingenRoot;
