import { InvalidationAction } from '@dvn/core/models/actions';
import { getCookieStorage } from '@dvn/kimlik/storage';
import { createMentornityApiInstance } from '../../../mentornity-js-client';
import { formViewWhiteLabelDelete, tableListViewWhiteLabel } from '../configs/view-configs';
import { mentornityApiEndpoint } from '../constants/env';
export class DeleteWhiteLabelFormHandler {
  constructor() {
    const { jwt, sessionId } = getCookieStorage().getAll();
    this.api = createMentornityApiInstance(mentornityApiEndpoint, {
      'Authorization': `Bearer ${jwt}`,
      'Client': 'd2ViLWFkbWlu',
      'Session-Token': sessionId,
    });
  }
  onSubmit(event) {
    const { values: { itemId } } = event.detail;
    return new Promise((resolve, reject) => {
      this.api.deleteWhiteLabel(itemId).then(() => {
        resolve({
          events: [
            new InvalidationAction(formViewWhiteLabelDelete.ID, tableListViewWhiteLabel.ID),
          ],
          navigation: {
            type: 'navigation',
            direction: 'back'
          }
        });
      }).catch(() => {
        reject(['Unexpected error']);
      });
    });
  }
}
