import { r as registerInstance, h, H as Host } from './index-55faf181.js';
import { C as CalendarUtils } from './calendar-33cf08b5.js';
import './kimlikApi-7350588e.js';
import './data-transfer-field-918730a3.js';
import './filter-cbaa3d7d.js';
import { e as InfoVisibility, c as createMentornityApiInstance, f as Config } from './instance-46ab1e99.js';
import { g as generateCalendarConfig, M as MentornityBridgeApi } from './mentorinty-bridge-api-946adc0d.js';
import { a as generateMembershipConfigForRole, g as getSessionDetails, c as getUser, d as getUserSettings, e as generateMembershipForRole, m as mentornityApiEndpoint } from './session-3ec0aa4c.js';
import { T as TitlePosition, I as ImagePosition } from './models-22fcdeab.js';
import { C as CompositeViewLinearConfig } from './composite-view-linear-config-b552b4ae.js';
import './index-ebde6a66.js';
import { T as TextField } from './index-403e215e.js';
import { I as InvalidationAction } from './actions-b9a0f808.js';
import { A as AppConfig } from './app-config-d490f9ae.js';
import { D as DetailViewConfig } from './detail-view-config-dafcc086.js';
import { T as TableConfig } from './table-config-5c917348.js';
import { A as AppViewType } from './view-config-39fd369a.js';
import { T as TakvimAvailableTimePickerViewConfig } from './takvim-available-time-picker-view-config-94465a89.js';
import { d as getMembershipFields, e as getUserDetailViewFieldConfigs } from './common-wrapper-util-36df331f.js';
import { a as AttachmentField } from './attachment-32decf79.js';
import './index-e6685442.js';
import './_commonjsHelpers-27f122dd.js';
import './moment-6f6ab70c.js';
import './BaseField-461b6d0c.js';
import './FieldModelGenerator-1ee7fda2.js';
import './index-6a1cf9c1.js';
import './date-ce777316.js';
import './index-083a6906.js';
import './index-fa1db470.js';
import './data-model-f5160369.js';
import './membership-61c4a2f7.js';
import './membership-config-a51a5232.js';
import './string-3065a411.js';
import './User-d2ee8b71.js';
import './CalendarConfig-184230a0.js';
import './UserSettings-7b80b841.js';
import './cookie-93ea205f.js';
import './index-d3bd30bd.js';

function getAppConfig(mentornityCookieContext, organisationConfig, language, viewedUserRole) {
  const showMessageButton = viewedUserRole === 'mentor'
    ? [
      InfoVisibility.allMentors,
      InfoVisibility.everyone,
    ].includes(organisationConfig.conversationPermissions.mentee)
    : [
      InfoVisibility.allMentees,
      InfoVisibility.everyone,
    ].includes(organisationConfig.conversationPermissions.mentor);
  const actions = [
    {
      ui: {
        componentTag: 'mentornity-follow-button',
        name: 'toggle-follow',
      },
      data: {
        mentornityCookieContext,
      }
    },
  ];
  if (showMessageButton) {
    actions.push({
      ui: {
        label: 'Send Message',
        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('name', ''),
            new TextField('initials', ''),
            new AttachmentField('imageUrl', ''),
          ],
          roleName: viewedUserRole,
          name: `${viewedUserRole}-detail-view`,
        }),
        ui: {
          cardConfig: {
            header: {
              title: {
                fieldId: 'name',
                position: TitlePosition.RightOfImage,
              },
              image: {
                fieldId: 'imageUrl',
                placeholderFieldId: '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',
        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',
            }
          }
        },
      }),
      TakvimAvailableTimePickerViewConfig.decode({
        _id: '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(config, viewedUserRole, mentornityCookieContext.role);
  const summaryCardFields = getUserDetailViewFieldConfigs(config, viewedUserRole, mentornityCookieContext.role, true, 3);
  const detailCardFields = getUserDetailViewFieldConfigs(config, viewedUserRole, mentornityCookieContext.role, true, 0);
  return DetailViewConfig.decode({
    _id: '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(userId, groupId, viewedUserRole) {
  return CompositeViewLinearConfig.decode({
    _id: 'mentornity-user-detail-page',
    table: {
      name: viewedUserRole === 'mentee' ? 'mentees' : 'mentors',
    },
    type: AppViewType.CompositeViewLinear,
    params: undefined,
    ui: {
      layout: 'vertical',
      views: [
        {
          viewId: 'user-detail-page-summary-card-view',
        },
        {
          title: 'INFO',
          viewId: 'user-detail-page-info-view',
        },
        {
          title: 'GET MEETING',
          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: 'MEETINGS',
          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',
            }
          },
        },
      ],
    }
  });
}

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

const MentornityUserDetailWrapper = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  componentWillLoad() {
    const { isZoomAuthenticated, language, timeFormat, timeZone, } = this;
    // set user's locale and time zone
    CalendarUtils.setLocale(language);
    CalendarUtils.setTimeFormat(timeFormat);
    CalendarUtils.setTimeZone(timeZone);
    const { context, headers } = getSessionDetails(this.groupId);
    this.mentornityCookieContext = context;
    this.user = getUser(context.userId);
    this.userSettings = getUserSettings(timeFormat, timeZone, language, isZoomAuthenticated);
    this.membership = generateMembershipForRole(context.role);
    this.mentornityBridgeApi = new MentornityBridgeApi(mentornityApiEndpoint, context, headers);
    createMentornityApiInstance(mentornityApiEndpoint, headers)
      .getOrganisationConfig(context.organisationId)
      .then((response) => {
      this.organisationConfig = Config.decode(response);
      this.mentornityBridgeApi.organisationConfig = Config.decode(response);
    });
  }
  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 { groupId, language, membership, mentornityBridgeApi, mentornityCookieContext, organisationConfig, user, userSettings, viewedUserId, viewedUserRole, } = this;
    if (!organisationConfig) {
      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", { apiData: mentornityBridgeApi, apiTakvim: mentornityBridgeApi, appConfig: getAppConfig(mentornityCookieContext, organisationConfig, language, viewedUserRole), params: {
        itemId: viewedUserId,
      }, user: user, userSettings: userSettings, membership: membership, view: getCompositeViewUIConfig(user._id, groupId, viewedUserRole) }))));
  }
};
MentornityUserDetailWrapper.style = mentornityUserDetailWrapperCss;

export { MentornityUserDetailWrapper as mentornity_user_detail_wrapper };
