import { r as registerInstance, h, H as Host } from './index-ecdfb761.js';
import { C as CalendarUtils } from './calendar-470c802a.js';
import { U as User } from './User-72c4643a.js';
import { S as SozlukApi } from './index-3bf9b308.js';
import './apiBase-6015f41f.js';
import './data-transfer-field-2f305919.js';
import './filter-cbaa3d7d.js';
import { l as generateMembershipConfigForRole, f as InfoVisibility, g as getSessionDetails, n as getUser, k as getUserSettings, m as mentornityApiEndpoint, c as createMentornityApiInstance, e as Config, d as generateMembershipForRole } from './session-2a491341.js';
import { g as generateCalendarConfig, a as getEmbeddedTranslation, M as MentornityBridgeApi } from './mentorinty-bridge-api-5ca2d652.js';
import { a as sozlukCalendarEntryEn, b as sozlukCalendarEntryTr, c as sozlukCalendarEntryPtBr, s as sozlukEntries } from './sozluk-entries-1e8f5234.js';
import { T as TitlePosition, I as ImagePosition } from './models-3a85e626.js';
import { C as CompositeViewLinearConfig } from './composite-view-linear-config-99947a0e.js';
import './index-e66e8eca.js';
import { T as TextField } from './index-150b6a59.js';
import { I as InvalidationAction } from './actions-b9a0f808.js';
import { A as AppConfig } from './app-config-9a584d70.js';
import { D as DetailViewConfig } from './detail-view-config-23af2b0d.js';
import { T as TableConfig } from './table-config-d73a72ab.js';
import { A as AppViewType } from './view-config-1ed8c59f.js';
import { T as TakvimAvailableTimePickerViewConfig } from './takvim-available-time-picker-view-config-816c103b.js';
import { d as getMembershipFields, e as getUserDetailViewFieldConfigs } from './common-wrapper-util-e4afa19b.js';
import { T as TakvimMeetingListViewConfig } from './takvim-meeting-list-view-config-aea8652b.js';
import { a as AttachmentField } from './attachment-961dd228.js';
import './index-a3ca021c.js';
import './_commonjsHelpers-27f122dd.js';
import './moment-65eca6b3.js';
import './data-model-88af49fc.js';
import './BaseField-0b01dc2c.js';
import './membership-b6639471.js';
import './string-3065a411.js';
import './UserSettings-7e4170a7.js';
import './cookie-5d9f5819.js';
import './kimlik-api-fddeac81.js';
import './index-d3bd30bd.js';
import './FieldModelGenerator-378c8613.js';
import './reference-field-a5b414d1.js';
import './index-61dcd269.js';
import './FieldGenerator-3ae403b2.js';
import './date-1bc489bd.js';
import './index-4e451db4.js';
import './index-23baeeef.js';
import './index-09efdc01.js';
import './CalendarConfig-412d1b0f.js';
import './i18n-09a07b97.js';
import './i18n-0e757ca5.js';

function getAppConfig(mentornityCookieContext, organisationConfig, language, userRole, viewedUserRole) {
  const showMessageButton = viewedUserRole === 'mentor'
    ? [
      InfoVisibility.allMentors,
      InfoVisibility.everyone,
    ].includes(organisationConfig.conversationPermissions.mentee)
    : [
      InfoVisibility.allMentees,
      InfoVisibility.everyone,
    ].includes(organisationConfig.conversationPermissions.mentor);
  const actions = [];
  if (userRole === 'mentee' && viewedUserRole === 'mentor') {
    // show follow buttons when mentee is viewing mentor detail
    actions.push({
      ui: {
        componentTag: 'mentornity-follow-button',
        name: 'toggle-follow',
      },
      data: {
        language,
        mentornityCookieContext,
      }
    });
  }
  if (showMessageButton) {
    actions.push({
      ui: {
        label: getEmbeddedTranslation(language, 'sendMessage'),
        name: 'send-message',
        view: 'flat'
      }
    });
  }
  return AppConfig.decode({
    views: [
      DetailViewConfig.decode({
        _id: 'user-detail-page-summary-card-view',
        type: AppViewType.DetailViewCard,
        table: TableConfig.decode({
          fields: [
            new TextField('user.name', ''),
            new TextField('user.initials', ''),
            new AttachmentField('user.imageUrl', ''),
          ],
          roleName: viewedUserRole,
          name: `${viewedUserRole}-detail-view`,
        }),
        ui: {
          cardConfig: {
            header: {
              title: {
                fieldId: 'user.name',
                position: TitlePosition.RightOfImage,
              },
              image: {
                fieldId: 'user.imageUrl',
                placeholderFieldId: 'user.initials',
                position: ImagePosition.BottomLeft,
              },
              cover: {
                // placeholder: 'https://thumbs.dreamstime.com/z/books-wooden-desk-table-abstract-background-education-copy-space-back-to-school-184388515.jpg',
                size: 88,
              },
            },
            footer: {
              actions,
            }
          }
        },
      }),
      getDetailViewUIConfig(mentornityCookieContext, language, organisationConfig, viewedUserRole),
      TakvimAvailableTimePickerViewConfig.decode({
        _id: 'user-detail-page-available-time-picker-view',
        i18nEntryId: 'user-detail-page-available-time-picker-view',
        type: AppViewType.TakvimAvailableTimePickerView,
        table: generateCalendarConfig(organisationConfig),
        events: {
          success: [
            new InvalidationAction('user-detail-page-available-time-picker-view', 'user-detail-page-meeting-list-view'),
          ]
        },
        successNavigationAction: {
          type: 'navigation',
          direction: 'forward',
          name: 'open-meeting-detail-after-creation',
          params: {
            conversionConfig: {
              'item._id': 'meetingId',
            }
          }
        },
      }),
      TakvimMeetingListViewConfig.decode({
        _id: 'user-detail-page-meeting-list-view',
        i18nEntryId: 'user-detail-page-meeting-list-view',
        type: AppViewType.TakvimMeetingListViewTable,
        table: generateCalendarConfig(organisationConfig),
      }),
    ]
  });
}
function getDetailViewUIConfig(mentornityCookieContext, language, config, viewedUserRole) {
  if (!config) {
    return null;
  }
  const fields = getMembershipFields(language, config, viewedUserRole, mentornityCookieContext.role);
  const summaryCardFields = getUserDetailViewFieldConfigs(language, config, viewedUserRole, mentornityCookieContext.role, true, 3);
  const detailCardFields = getUserDetailViewFieldConfigs(language, config, viewedUserRole, mentornityCookieContext.role, false, 0);
  return DetailViewConfig.decode({
    _id: 'user-detail-page-info-view',
    i18nEntryId: 'user-detail-page-info-view',
    type: AppViewType.DetailViewCard,
    table: TableConfig.decode({
      fields,
      roleName: viewedUserRole,
      name: `${viewedUserRole}-detail-view`,
    }),
    ui: {
      summaryCardConfig: {
        body: {
          fields: summaryCardFields,
        }
      },
      cardConfig: {
        body: {
          fields: detailCardFields,
        }
      },
    },
  });
}
function getCompositeViewUIConfig(organisationConfig, language, userId, groupId, userRole, viewedUserRole) {
  const views = [
    {
      viewId: 'user-detail-page-summary-card-view',
    },
    {
      title: getEmbeddedTranslation(language, 'info').toLocaleUpperCase(),
      viewId: 'user-detail-page-info-view',
    }
  ];
  const mentorViewingMenteeProfileInOneToOneProgram = userRole === 'mentor' && viewedUserRole === 'mentee'
    && organisationConfig.menteeType !== 'group';
  // no need to check if it's one-to-one because mentees can view their group's meetings in mentor detail page
  const menteeViewingMentorProfile = userRole === 'mentee' && viewedUserRole === 'mentor';
  if (mentorViewingMenteeProfileInOneToOneProgram || menteeViewingMentorProfile) {
    views.push({
      title: getEmbeddedTranslation(language, 'getMeeting').toLocaleUpperCase(),
      viewId: 'user-detail-page-available-time-picker-view',
      params: {
        viewedUserMembershipConfig: generateMembershipConfigForRole(viewedUserRole),
        conversionConfig: {
          // viewedUserMembership will be provided by
          // the dvn-app-view-composite-view-linear with the name 'item'
          // we're setting the conversion config to convert the 'item' into 'viewedUserMembership'
          item: 'viewedUserMembership',
        }
      },
    }, {
      title: getEmbeddedTranslation(language, 'meetings').toLocaleUpperCase(),
      viewId: 'user-detail-page-meeting-list-view',
      params: {
        guest1Id: groupId || userId,
        conversionConfig: {
          // viewedUserMembership will be provided by
          // the dvn-app-view-composite-view-linear with the name 'item'
          // we're setting the conversion config to convert the 'item.user._id' into 'guest2Id'
          'item.user._id': 'guest2Id',
        }
      },
    });
  }
  return CompositeViewLinearConfig.decode({
    _id: 'mentornity-user-detail-page',
    table: {
      name: viewedUserRole === 'mentee' ? 'mentees' : 'mentors',
    },
    type: AppViewType.CompositeViewLinear,
    params: undefined,
    ui: {
      layout: 'vertical',
      views,
    }
  });
}

const mentornityUserDetailWrapperCss = "mentornity-user-detail-wrapper{display:block}";

const MentornityUserDetailWrapper = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.weekStartDay = 'monday';
  }
  componentWillLoad() {
    const { isZoomAuthenticated, isGoogleAuthenticated, isMicrosoftBusinessAuthenticated, language, timeFormat, dateFormat, timeZone, weekStartDay, groupId, viewedUserRole, } = this;
    // set user's locale and time zone
    CalendarUtils.setTimeFormat(timeFormat);
    CalendarUtils.setDateFormat(dateFormat);
    CalendarUtils.setTimeZone(timeZone);
    switch (language) {
      case 'pt-br':
        CalendarUtils.setLocale(language, sozlukCalendarEntryPtBr, weekStartDay);
        break;
      case 'tr':
        CalendarUtils.setLocale(language, sozlukCalendarEntryTr, weekStartDay);
        break;
      default:
        CalendarUtils.setLocale(language, sozlukCalendarEntryEn, weekStartDay);
        break;
    }
    this.apiSozluk = new SozlukApi().setLanguage(language).setContents(sozlukEntries);
    const { context, headers } = getSessionDetails(this.groupId);
    const { userId, role } = context;
    this.user = getUser(userId);
    this.userSettings = getUserSettings(timeFormat, dateFormat, timeZone, language, isZoomAuthenticated, isGoogleAuthenticated, isMicrosoftBusinessAuthenticated);
    this.mentornityBridgeApi = new MentornityBridgeApi(mentornityApiEndpoint, context, headers);
    const mentornityApi = createMentornityApiInstance(mentornityApiEndpoint, headers);
    mentornityApi.get('users', context.userId)
      .then(user => this.user = User.decode(user));
    mentornityApi
      .getOrganisationConfig(context.organisationId)
      .then((config) => {
      this.organisationConfig = Config.decode(config);
      this.mentornityBridgeApi.organisationConfig = Config.decode(config);
      if (context.role === 'mentee' && this.organisationConfig.menteeType === 'group') {
        this.membership = generateMembershipForRole('group');
      }
      else {
        this.membership = generateMembershipForRole(context.role);
      }
      this.guestToPassToAvailableTimePickerAsCurrentUser = this.user;
      if (context.role === 'mentee' && config.menteeType === 'group') {
        // fetch the group of the mentee and set as the guest instead of the mentee
        if (context.groupId) {
          mentornityApi.getGroup(context.groupId).then(group => {
            if (group) {
              this.guestToPassToAvailableTimePickerAsCurrentUser = Object.assign(Object.assign({}, group), { name: group.title, initials: group.title[0] });
            }
          });
        }
        else {
          this.guestToPassToAvailableTimePickerAsCurrentUser = undefined;
        }
      }
      this.appConfig = getAppConfig(context, this.organisationConfig, language, role, viewedUserRole);
      this.compositeViewUIConfig = getCompositeViewUIConfig(this.organisationConfig, language, userId, groupId, role, viewedUserRole);
    });
  }
  onAction(event) {
    const action = event.detail;
    switch (action.name) {
      case 'send-message':
        // called when user clicks the "Send Message" button from the detail page
        window.dispatchEvent(new CustomEvent('dvn.mentornity-user-detail-wrapper.send-message', {
          detail: {
            user: action.params.item,
          }
        }));
        break;
      case 'open-meeting-detail-after-creation':
      case 'open-meeting-detail-from-meeting-list':
        window.dispatchEvent(new CustomEvent('dvn.mentornity-user-detail-wrapper.open-meeting-detail', {
          detail: {
            meetingId: action.params.meetingId,
          }
        }));
        break;
    }
  }
  render() {
    const { compositeViewUIConfig, appConfig, membership, mentornityBridgeApi, organisationConfig, userSettings, viewedUserId, user, } = this;
    if (!organisationConfig || !user) {
      return (h("div", { class: "d-flex justify-content-center pt-3" }, h("dvn-progress", { indefinite: true })));
    }
    return (h(Host, null, h("mentornity-root-wrapper", null, h("dvn-app-view-composite-view-linear", { apiSozluk: this.apiSozluk, apiData: mentornityBridgeApi, apiTakvim: mentornityBridgeApi, appConfig: appConfig, params: {
        itemId: viewedUserId,
      }, user: this.guestToPassToAvailableTimePickerAsCurrentUser, userSettings: userSettings, membership: membership, view: compositeViewUIConfig }))));
  }
};
MentornityUserDetailWrapper.style = mentornityUserDetailWrapperCss;

export { MentornityUserDetailWrapper as mentornity_user_detail_wrapper };
