var __rest = (this && this.__rest) || function (s, e) {
  var t = {};
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
    t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
import { InvalidationAction } from '@dvn/core/models/actions';
import { getCookieStorage } from '@dvn/kimlik/storage';
import { createMentornityApiInstance } from '../../../mentornity-js-client';
import { formViewWhiteLabelCreate, tableListViewWhiteLabel, } from '../configs/view-configs';
import { mentornityApiEndpoint } from '../constants/env';
export class EditWhiteLabelThemeFormHandler {
  constructor() {
    const { jwt, sessionId } = getCookieStorage().getAll();
    this.api = createMentornityApiInstance(mentornityApiEndpoint, {
      'Authorization': `Bearer ${jwt}`,
      'Client': 'd2ViLWFkbWlu',
      'Session-Token': sessionId,
    });
  }
  onSubmit(event) {
    const { values } = event.detail;
    return new Promise((resolve, reject) => {
      const { item } = values, formValues = __rest(values, ["item"]);
      const { primaryColor, primaryColorDark, accentColor, navBarTitleColor, } = formValues;
      const { _id } = item, rest = __rest(item, ["_id"]);
      this.api.updateWhiteLabel(item._id, Object.assign(Object.assign({ 
        // these are empty values to pass api validation
        'landingPageUrl': '', 'facebookUrl': '', 'twitterUrl': '', 'linkedInUrl': '', 'webSiteUrl': '', 'faviconUrl': '', 'appBarLogoUrl': '', organisations: [] }, rest), { theme: {
          primaryColor,
          primaryColorDark,
          accentColor,
          navBarTitleColor
        } })).then(() => {
        resolve({
          events: [
            new InvalidationAction(formViewWhiteLabelCreate.ID, tableListViewWhiteLabel.ID),
          ],
          navigation: {
            type: 'navigation',
            direction: 'back'
          }
        });
      }).catch(error => {
        console.log(error);
        reject(['Unexpected error']);
      });
    });
  }
}
