'use strict';

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

const index = require('./index-1141a245.js');
const i18n = require('./i18n-0bcf144d.js');
const index$1 = require('./index-a2e99c85.js');
const calendar = require('./calendar-e4b7baeb.js');
const string = require('./string-de672b69.js');
const mentorintyBridgeApi = require('./mentorinty-bridge-api-b1eaa56d.js');
require('./index-b776fc14.js');
require('./_commonjsHelpers-206db00d.js');
require('./moment-7a3433f2.js');
require('./apiBase-6c66ff1b.js');
require('./data-transfer-field-e8417d5f.js');
require('./BaseField-381327a9.js');
require('./filter-d5040f65.js');
require('./FieldModelGenerator-d61f01d4.js');
require('./reference-field-1239b0c3.js');
require('./index-2eea69a0.js');
require('./FieldGenerator-279a646b.js');
require('./date-a24d7714.js');
require('./index-0783d14f.js');
require('./index-9d3d3d15.js');
require('./index-9fd84b93.js');
require('./index-61f9621a.js');
require('./index-b7855ed6.js');
require('./attachment-a0cdf203.js');
require('./data-model-01c368bc.js');
require('./membership-e87e02ed.js');
require('./table-config-969d3038.js');
require('./User-dbfbd45e.js');
require('./CalendarConfig-998f742e.js');

const mentornityAnnouncementsWidgetCss = "mentornity-announcements-widget .announcement-content{display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;-ms-flex-align:center;align-items:center;cursor:pointer}mentornity-announcements-widget .break-line{height:1px;width:100%;color:var(--color-background-secondary);margin:calc(3 * var(--spacing-unit)) 0}mentornity-announcements-widget .announcement-title{color:var(--color-text)}mentornity-announcements-widget .content::-webkit-scrollbar{width:calc(3 * var(--spacing-unit))}mentornity-announcements-widget .content::-webkit-scrollbar-track{background-color:var(--color-tooltip-text);border-radius:100px}mentornity-announcements-widget .content::-webkit-scrollbar-thumb{background-color:var(--color-text-secondary);border-radius:100px}";

const MentornityAnnouncementsWidget = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.showAnnouncementDetailsDialog = false;
    this.expandAnnouncementsList = false;
  }
  async componentWillLoad() {
    this.strings = await this.apiSozluk.getContent(i18n.MentornityAnnouncementsWidgetI18nKey, i18n.mentornityAnnouncementsWidgetI18nDefault);
  }
  render() {
    var _a, _b;
    const { announcements, expandAnnouncementsList, isPending, strings } = this;
    const announcementsLength = announcements === null || announcements === void 0 ? void 0 : announcements.length;
    const hasAnnouncements = announcementsLength > 0;
    if (isPending) {
      return (index.h(index.Host, null, index.h("b", { class: "pl-3", style: { fontSize: '1.1rem' } }, strings.announcements), index.h("dvn-card", { elevation: 1 }, index.h("div", { class: "d-flex justify-content-center" }, index.h("dvn-progress", { indefinite: true, tint: "primary" })))));
    }
    return (index.h(index.Host, null, index.h("b", { class: "pl-3", style: { fontSize: '1.1rem' } }, strings.announcements), index.h("dvn-card", { elevation: 1 }, announcements.map((announcement, i) => {
      if (i >= 5 && !expandAnnouncementsList)
        return;
      return (index.h("div", null, index.h("div", { class: "announcement-content", onClick: () => {
          this.selectedAnnouncement = announcement;
          this.showAnnouncementDetailsDialog = true;
        } }, index.h("h4", { class: "announcement-title" }, " ", announcement.title, " "), index.h("dvn-icon", { "icon-name": "uil uil-angle-right-b", size: 35 })), announcementsLength - 1 !== i &&
        index.h("hr", { class: "break-line" })));
    }), announcementsLength > 5 && !expandAnnouncementsList &&
      index.h("dvn-card-footer", { class: "mt-3", slot: "footer", alignRight: true }, index.h("dvn-button", { leaned: true, view: "flat", onClick: () => {
          this.expandAnnouncementsList = true;
        } }, strings.seeAll)), !hasAnnouncements &&
      index.h("div", { class: "col-md-12" }, index.h("p", { class: "m-0" }, " ", strings.emptyMessage, " ")), index.h("dvn-dialog", { title: (_a = this.selectedAnnouncement) === null || _a === void 0 ? void 0 : _a.title, shown: this.showAnnouncementDetailsDialog, onDismiss: () => this.showAnnouncementDetailsDialog = false, separateHeader: true }, index.h("dvn-markdown", { content: (_b = this.selectedAnnouncement) === null || _b === void 0 ? void 0 : _b.content })))));
  }
};
MentornityAnnouncementsWidget.style = mentornityAnnouncementsWidgetCss;

const mentornityPairMeetingSummaryWidgetCss = "mentornity-pair-meeting-summary-widget .user-card{margin-bottom:1rem}mentornity-pair-meeting-summary-widget .user-card:nth-last-child(-n+2){margin-bottom:0}mentornity-pair-meeting-summary-widget .header{white-space:nowrap;margin-bottom:calc(3 * var(--spacing-unit))}mentornity-pair-meeting-summary-widget .header dvn-image{float:left}mentornity-pair-meeting-summary-widget .header dvn-linear-progress,mentornity-pair-meeting-summary-widget .header h5,mentornity-pair-meeting-summary-widget .header p,mentornity-pair-meeting-summary-widget .header a{font-size:0.9rem;position:relative;top:var(--spacing-unit);left:calc(2 * var(--spacing-unit))}mentornity-pair-meeting-summary-widget .header p{padding:0;margin:0 0 0 50px;color:var(--color-text-secondary)}mentornity-pair-meeting-summary-widget .header a{margin:0;padding:0;color:#000}mentornity-pair-meeting-summary-widget .clickable:hover{text-decoration:underline;cursor:pointer;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content}";

const MentornityPairsMeetingWidget = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.action = index.createEvent(this, "action", 7);
    this.isPending = true;
  }
  async componentWillLoad() {
    this.strings = await this.apiSozluk.getContent(i18n.MentornityPairsMeetingWidgetI18nKey, i18n.mentornityPairsMeetingWidgetI18nDefault);
  }
  render() {
    const { activePairs, isPending, meetingGoalConfig, menteeType, organisationConfig, requestedPairs, strings, userType, } = this;
    if (isPending) {
      return (index.h(index.Host, null, index.h("b", { class: "pl-3", style: { fontSize: '1.1rem' } }, strings.myPairs), index.h("dvn-card", { elevation: 1 }, index.h("div", { class: "d-flex justify-content-center" }, index.h("dvn-progress", { indefinite: true, tint: "primary" })))));
    }
    // get pairs type
    let pairsType;
    if (userType === 'mentee') {
      pairsType = 'mentor';
    }
    else {
      pairsType = menteeType === 'group' ? 'group' : 'mentee';
    }
    const isMentorSelectionOn = organisationConfig.subscriptionConfig.mentorVisibilityStatus === 'showAvailableMentors';
    const hasPendingRequest = (requestedPairs === null || requestedPairs === void 0 ? void 0 : requestedPairs.length) > 0;
    const hasActivePairs = (activePairs === null || activePairs === void 0 ? void 0 : activePairs.length) > 0;
    const showCardFooter = hasActivePairs || isMentorSelectionOn;
    const showPendingPairRequestAlert = isMentorSelectionOn && hasPendingRequest;
    const showPairList = hasActivePairs;
    const seeRequestsLabel = userType === 'mentee' ? strings.goToSelectionPage : strings.seeRequests;
    const messages = [];
    if (!hasActivePairs) {
      messages.push(strings.notMatchedMessage);
      if (userType === 'mentee') {
        if (isMentorSelectionOn) {
          messages.push(strings.pairsEmptyRequestOpenMessage);
        }
        else {
          messages.push(strings.pairsEmptyRequestOffMessage);
        }
      }
      else {
        if (isMentorSelectionOn) {
          if (hasPendingRequest) {
            messages.push(strings.pairsHasRequestEmptyMessage);
          }
          else {
            messages.push(strings.pairsHasNotRequestEmptyMessage);
          }
        }
        else {
          messages.push(strings.pairsEmptyRequestOffMessage);
        }
      }
    }
    const showMessages = messages.length > 0;
    const goToPairsActionName = userType === 'mentor' ? 'go-to-mentees-page' : 'go-to-mentors-page';
    const goToPairsPage = () => this.action.emit({ name: goToPairsActionName });
    const goToPairSelectionPage = () => this.action.emit({ name: 'go-to-mentor-selection' });
    const goToUserPairPage = (user) => {
      var _a;
      return this.action.emit({
        name: 'go-to-pair-detail-page',
        params: { uid: user._id, subId: (_a = user.subscription) === null || _a === void 0 ? void 0 : _a._id }
      });
    };
    return (index.h(index.Host, null, index.h("b", { class: "pl-3", style: { fontSize: '1.1rem' } }, strings.myPairs), index.h("dvn-card", { elevation: 1 }, showPendingPairRequestAlert &&
      index.h("dvn-alert", { message: index$1.SozlukApi.build(strings.waitingForResponse, {
          count: requestedPairs.length,
          // data will only show when the language is English
          plural: requestedPairs.length > 1 ? 's' : '',
          verb: requestedPairs.length > 1 ? 'are' : 'is'
        }) }), showPairList &&
      index.h("div", { class: "row" }, activePairs.map(generatePairView(strings, pairsType, meetingGoalConfig, goToUserPairPage))), showMessages &&
      index.h("div", { class: "col-md-12" }, messages.length > 0 && messages.map(text => (index.h("p", { class: "m-0" }, text)))), showCardFooter &&
      index.h("dvn-card-footer", { slot: "footer", alignRight: true }, hasActivePairs &&
        index.h("dvn-button", { leaned: true, view: "flat", onClick: () => goToPairsPage() }, strings.seeAll), isMentorSelectionOn &&
        index.h("dvn-button", { leaned: true, view: "flat", onClick: () => {
            if (userType === 'mentee') {
              goToPairSelectionPage();
            }
            else {
              goToPairsPage();
            }
          } }, seeRequestsLabel)))));
  }
};
const generatePairView = (strings, pairsType, meetingGoalConfig, goToUserPairPage) => (pair, i) => {
  var _a;
  if (i >= 6) {
    return;
  }
  const { user, meetings } = pair;
  const hasMeetings = meetings.length > 0;
  const hasMeetingGoal = meetingGoalConfig && ((_a = meetingGoalConfig.meetingGoals) === null || _a === void 0 ? void 0 : _a.length) > 0;
  const shortName = pairsType === 'group'
    ? user.title[0]
    : user.firstName[0] + user.lastName[0];
  return (index.h("div", { class: "col-lg-6 col-md-12 user-card" }, index.h("div", { class: "header" }, index.h("dvn-image", { slot: "media", src: user.imageUrl, text: shortName, leaned: true, shape: "circle", size: 50 }), index.h("b", { class: "clickable pl-2", onClick: () => goToUserPairPage(user) }, pairsType === 'group' ? user.title : user.firstName + ' ' + user.lastName), hasMeetingGoal &&
    index.h("dvn-linear-progress", { showPercent: hasMeetings, percent: calculateMeetingsPercent(meetings, hasMeetings, meetingGoalConfig), scale: "small" }), index.h("p", { class: "clickable", onClick: () => goToUserPairPage(user) }, hasMeetings ? `${meetings.length} ${strings.meetings}` : strings.scheduleMeeting))));
};
const calculateMeetingsPercent = (meetings, hasMeetings, meetingGoalConfig) => {
  var _a;
  if (!hasMeetings) {
    return '0';
  }
  const totalMeetings = (_a = meetingGoalConfig.meetingGoals) === null || _a === void 0 ? void 0 : _a.length;
  let placedMeetings = meetings === null || meetings === void 0 ? void 0 : meetings.length;
  const result = Math.floor((placedMeetings / totalMeetings) * 100).toString();
  return result;
};
MentornityPairsMeetingWidget.style = mentornityPairMeetingSummaryWidgetCss;

const mentornityPastMeetingsWidgetCss = "mentornity-past-meetings-widget .meeting-date{font-weight:bold;color:var(--color-text);max-width:-webkit-min-content;max-width:-moz-min-content;max-width:min-content;max-height:80px;word-wrap:break-word;border:var(--color-text) 2px solid;border-radius:var(--corner-radius);padding:calc(2 * var(--spacing-unit));text-align:center;cursor:pointer}mentornity-past-meetings-widget .meeting-date .meeting-year{font-weight:100}mentornity-past-meetings-widget .full-name{color:var(--color-text);font-weight:bold}mentornity-past-meetings-widget .meeting-data{font-size:var(--font-size-medium);height:-webkit-fit-content;height:-moz-fit-content;height:fit-content;-ms-flex-align:center;align-items:center}mentornity-past-meetings-widget .break-line{height:1px;color:var(--color-background-secondary)}mentornity-past-meetings-widget .video-icon i::before{margin:0}mentornity-past-meetings-widget .clickable{cursor:pointer}mentornity-past-meetings-widget .custom-address{color:var(--color-text-title)}mentornity-past-meetings-widget .meeting-time{font-size:var(--font-size-medium)}mentornity-past-meetings-widget .fill-error{color:var(--color-danger)}mentornity-past-meetings-widget .clickable:hover{cursor:pointer;text-decoration:underline}mentornity-past-meetings-widget .meeting-goal-title h3{margin:0}mentornity-past-meetings-widget p{margin:0}";

const formErrors = (error) => {
  if (!error)
    return [];
  // TODO show proper error messages from apiSozluk
  return [
    string.capitalize(`${error.data.message.split('-').join(' ')}.`, false),
  ];
};
const MentornityPastMeetingsWidget = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.action = index.createEvent(this, "action", 7);
    this.toggleSeeAllButton = false;
    this.isProgressing = false;
    this.createResponseFormError = undefined;
    this.isPending = true;
    this.goToMeetingDetails = (meeting) => this.action.emit({
      name: 'go-to-meeting-page',
      params: { meetingId: meeting._id }
    });
    this.formFields = () => {
      var _a;
      const fields = (_a = this.feedbackConfig) === null || _a === void 0 ? void 0 : _a.fields.map(field => mentorintyBridgeApi.convertMentornityFieldToDevingenField(field));
      return { fields };
    };
    this.onSubmitForm = async (event) => {
      const data = event.detail.values;
      if (Object.keys(data).length === 0) {
        return;
      }
      const formResponse = {
        data: Object.assign({}, data),
        event: { _type: 'reference', _class: 'events', _id: this.selectedForm._id },
        organisation: { _type: 'reference', _class: 'organisations', _id: this.selectedForm.organisation._id },
        type: 'feedback',
      };
      if (this.groupId) {
        formResponse.group = { _type: 'reference', _class: 'groups', _id: this.groupId };
      }
      this.isProgressing = true;
      this.createResponseFormError = undefined;
      this.api.createFormResponse(formResponse)
        .then(async () => {
        // fetch the meetings again
        const data = await this.fetchPastMeetings(this.context);
        this.isProgressing = false;
        this.meetings = data.meetings;
        this.unfilledFormCount = data.unfilledFormCount;
        // to close modal
        this.selectedForm = null;
      })
        .catch(err => this.createResponseFormError = err);
    };
    this.generatePastmeetingView = (meetings, account, groupId, timeFormat, meetingGoalConfig, meetingsLength, expandMeetings, strings, goToMeetingDetails) => {
      var _a;
      const hasMeetingGoal = meetingGoalConfig && ((_a = meetingGoalConfig.meetingGoals) === null || _a === void 0 ? void 0 : _a.length) > 0;
      // filter nearest meetings
      meetings = meetings.sort((a, b) => {
        return b.startDate * 1000 - a.startDate * 1000;
      });
      const generatedMeetings = generateMeetings$1(meetings, expandMeetings);
      return (index.h("div", null, generatedMeetings.map((meeting, i) => {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
        const meetingDayAndMonth = calendar.CalendarUtils.format(new Date(meeting.startDate * 1000), 'MMM DD');
        const meetingYear = calendar.CalendarUtils.format(new Date(meeting.startDate * 1000), 'YYYY');
        const startDate = calendar.CalendarUtils.format(new Date(meeting.startDate * 1000), `ddd ${timeFormat === '12-hour' ? 'hh:mm A' : 'HH:mm'}`);
        const endDate = calendar.CalendarUtils.format(new Date(meeting.endDate * 1000), `${timeFormat === '12-hour' ? 'hh:mm A' : 'HH:mm'}`);
        const guests = meeting.guests;
        const mentor = guests[0];
        const mentee = guests[1];
        const isAccountMentor = mentor._id === account._id;
        const isMenteeUser = mentee._class === 'users' || mentee.firstName;
        const isMenteeGroup = mentee._class === 'groups' || !mentee.firstName;
        const isAccountMenteeInMeeting = isMenteeUser && !!guests.find(m => m._id === account._id);
        const isGroupMenteeInMeeting = isMenteeGroup && groupId && !!guests.find(m => m._id === groupId); // eslint-disable-line max-len
        let fullName = '';
        if (account && isAccountMentor) {
          if (isMenteeUser) {
            fullName = `${mentee.firstName} ${mentee.lastName}`;
          }
          else if (isMenteeGroup) {
            if (((_a = meeting.guests) === null || _a === void 0 ? void 0 : _a.length) > 2) {
              for (let i = 1; i < ((_b = meeting.guests) === null || _b === void 0 ? void 0 : _b.length); i++) {
                fullName += meeting.guests[i].title;
                fullName = ((_c = meeting.guests) === null || _c === void 0 ? void 0 : _c.length) - 1 !== i
                  ? fullName.concat(', ')
                  : fullName;
              }
              fullName = truncate$2(fullName, 40);
            }
            else {
              fullName = mentee.title;
            }
          }
        }
        else if (account && (isAccountMenteeInMeeting || isGroupMenteeInMeeting)) {
          fullName = `${mentor.firstName} ${mentor.lastName}`;
        }
        const meetingTime = startDate + ' - ' + endDate;
        const displayBreakLine = i < meetingsLength - 1;
        const meetingLocation = `${((_e = (_d = meeting.location) === null || _d === void 0 ? void 0 : _d.type) === null || _e === void 0 ? void 0 : _e.charAt(0).toUpperCase()) + ((_g = (_f = meeting.location) === null || _f === void 0 ? void 0 : _f.type) === null || _g === void 0 ? void 0 : _g.slice(1))} ${strings.meet}`;
        const ownSession = hasMeetingGoal && (meetingGoalConfig === null || meetingGoalConfig === void 0 ? void 0 : meetingGoalConfig.meetingGoals.find(session => session.identifier === meeting.meetingGoalIdentifier));
        const hasFeedback = !!((_h = meeting === null || meeting === void 0 ? void 0 : meeting.feedback) === null || _h === void 0 ? void 0 : _h._id) || ((_j = meeting === null || meeting === void 0 ? void 0 : meeting.feedback) === null || _j === void 0 ? void 0 : _j.length) > 0;
        // check if session has a questions
        let sessionHasQuestions = false;
        if (hasMeetingGoal) {
          const session = ownSession === null || ownSession === void 0 ? void 0 : ownSession.specifications[this.userType];
          sessionHasQuestions = ((_l = (_k = session === null || session === void 0 ? void 0 : session.postMeetingForm) === null || _k === void 0 ? void 0 : _k.fields) === null || _l === void 0 ? void 0 : _l.length) > 0 || ((_o = (_m = session === null || session === void 0 ? void 0 : session.preMeetingForm) === null || _m === void 0 ? void 0 : _m.fields) === null || _o === void 0 ? void 0 : _o.length) > 0;
        }
        return (index.h("div", null, hasMeetingGoal &&
          index.h("div", { class: "meeting-goal-title" }, index.h("h3", null, " ", ownSession === null || ownSession === void 0 ? void 0 :
            ownSession.meetingTitle, " ")), index.h("div", { class: "d-flex justify-content-between align-items-center mt-2" }, index.h("div", { class: "d-flex meeting-data" }, index.h("p", { class: "meeting-date", onClick: () => goToMeetingDetails(meeting) }, " ", index.h("span", { class: "meeting-year" }, meetingYear), " ", index.h("span", null, meetingDayAndMonth), " "), index.h("div", { class: "flex-column ml-3" }, ((hasMeetingGoal && sessionHasQuestions && !hasFeedback) || (!hasMeetingGoal && !hasFeedback)) &&
          index.h("div", { class: "d-flex align-items-center clickable fill-error", onClick: () => {
              if (!hasMeetingGoal)
                this.selectedForm = Object.assign(Object.assign({}, meeting), { index: i });
              else
                goToMeetingDetails(meeting);
            } }, index.h("p", null, strings.fillForm), index.h("dvn-icon", { iconName: `uil uil-edit-alt`, scale: "large" })), index.h("div", { class: "full-name" }, index.h("p", null, " ", fullName, " ")), index.h("div", { class: "meeting-time" }, index.h("p", null, " ", meetingTime, " ")), index.h("div", { class: "d-flex align-items-center text-primary" }, meeting.location.type === 'custom' || meeting.location.type === undefined ?
          index.h("p", { class: "custom-address" }, " ", truncate$2(meeting.location.address, 30), " ")
          :
            index.h("div", { class: "d-flex align-items-center" }, index.h("dvn-icon", { "icon-name": "uil uil-video", scale: "large", size: 20, class: "video-icon" }), index.h("a", { class: "ml-2", target: '_blank', href: meeting.location.address }, " ", meetingLocation, " "))))), index.h("dvn-icon", { onClick: () => goToMeetingDetails(meeting), class: "clickable", "icon-name": "uil uil-angle-right-b", size: 35 })), displayBreakLine &&
          index.h("hr", { class: "break-line" })));
      })));
    };
  }
  async componentWillLoad() {
    this.strings = await this.apiSozluk.getContent(i18n.MentornityPastMeetingWidgetI18nKey, i18n.mentornityPastMeetingWidgetI18nDefault);
  }
  render() {
    var _a, _b;
    const { meetings, timeFormat, strings, isPending, meetingGoalConfig, account, groupId, isProgressing, createResponseFormError, unfilledFormCount, unfilledSessionFormCount } = this;
    const { fields: meetingDetailsFormFields } = this.formFields();
    const hasMeetings = (meetings === null || meetings === void 0 ? void 0 : meetings.length) > 0;
    const hasMeetingGoal = meetingGoalConfig && ((_a = meetingGoalConfig.meetingGoals) === null || _a === void 0 ? void 0 : _a.length) > 0;
    if (isPending) {
      return (index.h(index.Host, null, index.h("b", { class: "pl-3", style: { fontSize: '1.1rem' } }, strings.pastMeetings), index.h("dvn-card", { elevation: 1 }, index.h("div", { class: "d-flex justify-content-center" }, index.h("dvn-progress", { indefinite: true, tint: "primary" })))));
    }
    const meetingsCount = hasMeetingGoal ? unfilledSessionFormCount : unfilledFormCount;
    return (index.h(index.Host, null, index.h("b", { class: "pl-3", style: { fontSize: '1.1rem' } }, strings.pastMeetings), index.h("dvn-card", { elevation: 1 }, ((hasMeetingGoal && unfilledSessionFormCount > 0) || (!hasMeetingGoal && unfilledFormCount > 0)) &&
      index.h("dvn-alert", { message: meetingsCount > 1 ?
          `${String(meetingsCount)} ${strings.formsAreWaiting}`
          :
            `${String(meetingsCount)} ${strings.formsIsWaiting}`, tint: "danger" }), meetings &&
      this.generatePastmeetingView(meetings, account, groupId, timeFormat, meetingGoalConfig, meetings === null || meetings === void 0 ? void 0 : meetings.length, this.toggleSeeAllButton, strings, this.goToMeetingDetails), (meetings === null || meetings === void 0 ? void 0 : meetings.length) > 3 && !this.toggleSeeAllButton &&
      index.h("dvn-card-footer", { class: "mt-3", slot: "footer", alignRight: true }, index.h("dvn-button", { leaned: true, view: "flat", onClick: () => {
          this.toggleSeeAllButton = true;
        } }, strings.seeAll, "(", meetings.length, ")")), !hasMeetings &&
      index.h("div", { class: "col-md-12" }, index.h("p", null, " ", strings.listMeetingsHere, " "), index.h("p", null, " ", strings.emptyMeetings, " "))), !hasMeetingGoal &&
      index.h("dvn-dialog", { title: strings.meetingQuestions, shown: !!this.selectedForm, onDismiss: () => {
          this.selectedForm = null;
          this.createResponseFormError = undefined;
        } }, index.h("doldurma-form", { key: (_b = this.selectedForm) === null || _b === void 0 ? void 0 : _b.index, fields: meetingDetailsFormFields, onSubmit: this.onSubmitForm, submitButtonLabel: strings.submit, progressing: isProgressing, formErrors: formErrors(createResponseFormError), width: '100%' }))));
  }
};
const generateMeetings$1 = (meetings, toggleSeeAllButton) => {
  if (!meetings)
    return [];
  // display only first 3 items
  if (!toggleSeeAllButton) {
    return meetings.slice(0, 3);
  }
  // display all item
  return meetings;
};
const truncate$2 = (text, limit) => {
  if (text.length > limit) {
    return text.substring(0, limit) + '...';
  }
  return text;
};
MentornityPastMeetingsWidget.style = mentornityPastMeetingsWidgetCss;

const mentornityProgramInfoWidgetCss = "mentornity-program-info-widget dvn-button button{margin:0 calc(2 * var(--spacing-unit)) 0 0}mentornity-program-info-widget .program-buttons{margin:var(--spacing-unit) 0 0 calc(3 * var(--spacing-unit))}mentornity-program-info-widget .content::-webkit-scrollbar{width:calc(3 * var(--spacing-unit))}mentornity-program-info-widget .content::-webkit-scrollbar-track{background-color:var(--color-tooltip-text);border-radius:100px}mentornity-program-info-widget .content::-webkit-scrollbar-thumb{background-color:var(--color-text-secondary);border-radius:100px}";

const MentornityProgramInfoWidget = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.expandInfo = false;
    this.showTermsDialog = false;
    this.renderProgramInfoCard = (showLearnMoreButton = true, forceTruncateInfo = false) => {
      const { organisation, expandInfo, organisationConfig, strings } = this;
      const truncateDesctription = expandInfo && !forceTruncateInfo ? organisation.description : truncate$1(organisation.description, 250);
      const termsContent = organisationConfig === null || organisationConfig === void 0 ? void 0 : organisationConfig.terms;
      return (index.h("dvn-card", { elevation: forceTruncateInfo ? 1 : 0, leaned: !forceTruncateInfo }, index.h("dvn-card-header", { title: organisation.title, "cover-src": organisation.coverUrl, coverAspectRatio: 3, slot: "header", "show-cover": true }), index.h("div", { class: {
          'program-buttons': expandInfo,
          'mb-3': true,
        }, slot: "header" }, index.h("a", { href: `/${organisation.domain}/welcome` }, index.h("dvn-button", { tint: "neutral", scale: "small" }, strings.onboardingSteps)), index.h("dvn-button", { tint: "neutral", scale: "small", onClick: () => this.showTermsDialog = true }, strings.terms)), index.h("dvn-markdown", { content: truncateDesctription }), index.h("div", { class: "mt-3" }, (organisation === null || organisation === void 0 ? void 0 : organisation.facebookUrl) && index.h("a", { href: addValidationToLink(organisation === null || organisation === void 0 ? void 0 : organisation.facebookUrl), target: "_blank" }, index.h("dvn-icon-button", { "icon-name": "uil uil-facebook", tint: "neutral", scale: "small" })), (organisation === null || organisation === void 0 ? void 0 : organisation.twitterUrl) && index.h("a", { href: addValidationToLink(organisation === null || organisation === void 0 ? void 0 : organisation.twitterUrl), target: "_blank" }, index.h("dvn-icon-button", { "icon-name": "uil uil-twitter", tint: "neutral", scale: "small" })), (organisation === null || organisation === void 0 ? void 0 : organisation.linkedInUrl) && index.h("a", { href: addValidationToLink(organisation === null || organisation === void 0 ? void 0 : organisation.linkedInUrl), target: "_blank" }, index.h("dvn-icon-button", { "icon-name": "uil uil-linkedin", tint: "neutral", scale: "small" })), (organisation === null || organisation === void 0 ? void 0 : organisation.webSiteUrl) && index.h("a", { href: addValidationToLink(organisation === null || organisation === void 0 ? void 0 : organisation.webSiteUrl), target: "_blank" }, index.h("dvn-icon-button", { "icon-name": "uil uil-globe", tint: "neutral", scale: "small" }))), showLearnMoreButton && organisation.description.length >= 250 &&
        index.h("dvn-card-footer", { "align-right": true, slot: "footer" }, index.h("dvn-button", { leaned: true, tint: "neutral", view: "flat", onClick: () => this.expandInfo = !expandInfo }, strings.learnMore)), index.h("dvn-dialog", { title: strings.programTerms, shown: this.showTermsDialog, onDismiss: () => this.showTermsDialog = false, separateHeader: true }, index.h("dvn-markdown", { content: termsContent }))));
    };
  }
  async componentWillLoad() {
    this.strings = await this.apiSozluk.getContent(i18n.MentornityProgramInfoWidgetI18nKey, i18n.mentornityProgramInfoWidgetI18nDefault);
  }
  render() {
    const { isPending, strings } = this;
    if (isPending) {
      return (index.h(index.Host, null, index.h("b", { class: "pl-3", style: { fontSize: '1.1rem' } }, strings.programInfo), index.h("dvn-card", { elevation: 1 }, index.h("div", { class: "d-flex justify-content-center" }, index.h("dvn-progress", { indefinite: true, tint: "primary" })))));
    }
    return (index.h(index.Host, null, index.h("b", { class: "pl-3", style: { fontSize: '1.1rem' } }, strings.programInfo), this.renderProgramInfoCard(true, true), index.h("dvn-dialog", { title: strings.programInfo, shown: this.expandInfo, onDismiss: () => this.expandInfo = false, separateHeader: true, raw: true }, this.renderProgramInfoCard(false))));
  }
};
const truncate$1 = (text, limit) => {
  if (text.length > limit) {
    return text.substring(0, limit) + '...';
  }
  return text;
};
const addValidationToLink = (link) => {
  return link.startsWith('http://') || link.startsWith('https://') ?
    link
    : `http://${link}`;
};
MentornityProgramInfoWidget.style = mentornityProgramInfoWidgetCss;

const mentornityUpcomingMeetingsWidgetCss = "mentornity-upcoming-meetings-widget .meeting-date{font-weight:bold;color:var(--color-text);max-width:6ch;max-height:80px;word-wrap:break-word;border:var(--color-text) 2px solid;border-radius:var(--corner-radius);padding:calc(2 * var(--spacing-unit));text-align:center;cursor:pointer}mentornity-upcoming-meetings-widget .full-name{color:var(--color-text);font-weight:bold}mentornity-upcoming-meetings-widget .meeting-data{font-size:var(--font-size-medium);height:-webkit-fit-content;height:-moz-fit-content;height:fit-content;-ms-flex-align:center;align-items:center}mentornity-upcoming-meetings-widget .break-line{height:1px;color:var(--color-background-secondary)}mentornity-upcoming-meetings-widget .video-icon i::before{margin:0}mentornity-upcoming-meetings-widget .clickable{cursor:pointer}mentornity-upcoming-meetings-widget .custom-address{color:var(--color-text-title)}mentornity-upcoming-meetings-widget .meeting-time{font-size:var(--font-size-medium)}mentornity-upcoming-meetings-widget .meeting-goal-title{margin-bottom:calc(4 * var(--spacing-unit))}mentornity-upcoming-meetings-widget .meeting-goal-title h3{margin-top:0 !important}mentornity-upcoming-meetings-widget p{margin:0}";

const MentornityUpcomingmeetingsWidget = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.action = index.createEvent(this, "action", 7);
    this.toggleSeeAllButton = false;
    this.isPending = true;
    this.goToMeetingDetails = (meeting) => this.action.emit({
      name: 'go-to-meeting-page',
      params: { meetingId: meeting._id }
    });
  }
  async componentWillLoad() {
    this.strings = await this.apiSozluk.getContent(i18n.MentornityUpcomingMeetingWidgetI18nKey, i18n.mentornityUpcomingMeetingWidgetI18nDefault);
  }
  render() {
    const { meetings, timeFormat, strings, isPending, meetingGoalConfig, account, groupId } = this;
    const hasMeetings = (meetings === null || meetings === void 0 ? void 0 : meetings.length) > 0;
    if (isPending) {
      return (index.h(index.Host, null, index.h("b", { class: "pl-3", style: { fontSize: '1.1rem' } }, strings.upcomingMeetings), index.h("dvn-card", { elevation: 1 }, index.h("div", { class: "d-flex justify-content-center" }, index.h("dvn-progress", { indefinite: true, tint: "primary" })))));
    }
    return (index.h(index.Host, null, index.h("b", { class: "pl-3", style: { fontSize: '1.1rem' } }, strings.upcomingMeetings), index.h("dvn-card", { elevation: 1 }, meetings &&
      generateUpcomingmeetingView(meetings, account, groupId, timeFormat, meetingGoalConfig, this.toggleSeeAllButton, strings, this.goToMeetingDetails), (meetings === null || meetings === void 0 ? void 0 : meetings.length) > 3 && !this.toggleSeeAllButton &&
      index.h("dvn-card-footer", { class: "mt-3", slot: "footer", alignRight: true }, index.h("dvn-button", { leaned: true, view: "flat", onClick: () => {
          this.toggleSeeAllButton = true;
        } }, strings.seeAll, "(", meetings.length, ")")), !hasMeetings &&
      index.h("div", { class: "col-md-12" }, index.h("p", null, " ", strings.listMeetingsHere, " "), index.h("p", null, " ", strings.emptyMeetings, " ")))));
  }
};
const generateUpcomingmeetingView = (meetings, account, groupId, timeFormat, meetingGoalConfig, expandMeetings, strings, goToMeetingDetails) => {
  var _a;
  const hasMeetingGoal = meetingGoalConfig && ((_a = meetingGoalConfig.meetingGoals) === null || _a === void 0 ? void 0 : _a.length) > 0;
  // filter nearest meetings
  meetings = meetings.sort((a, b) => {
    return a.startDate * 1000 - b.startDate * 1000;
  });
  const generatedMeetings = generateMeetings(meetings, expandMeetings);
  return (index.h("div", null, generatedMeetings.map((meeting, i) => {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
    const meetingDate = calendar.CalendarUtils.format(new Date(meeting.startDate * 1000), 'MMM DD');
    const startDate = calendar.CalendarUtils.format(new Date(meeting.startDate * 1000), `ddd ${timeFormat === '12-hour' ? 'hh:mm A' : 'HH:mm'}`);
    const endDate = calendar.CalendarUtils.format(new Date(meeting.endDate * 1000), `${timeFormat === '12-hour' ? 'hh:mm A' : 'HH:mm'}`);
    const guests = meeting.guests;
    const mentor = guests[0];
    const mentee = guests[1];
    const isAccountMentor = mentor._id === account._id;
    const isMenteeUser = mentee._class === 'users' || mentee.firstName;
    const isMenteeGroup = mentee._class === 'groups' || !mentee.firstName;
    const isAccountMenteeInMeeting = isMenteeUser && !!guests.find(m => m._id === account._id);
    const isGroupMenteeInMeeting = isMenteeGroup && groupId && !!guests.find(m => m._id === groupId); // eslint-disable-line max-len
    let fullName = '';
    if (account && isAccountMentor) {
      if (isMenteeUser) {
        fullName = `${mentee.firstName} ${mentee.lastName}`;
      }
      else if (isMenteeGroup) {
        if (((_a = meeting.guests) === null || _a === void 0 ? void 0 : _a.length) > 2) {
          for (let i = 1; i < ((_b = meeting.guests) === null || _b === void 0 ? void 0 : _b.length); i++) {
            fullName += meeting.guests[i].title;
            fullName = ((_c = meeting.guests) === null || _c === void 0 ? void 0 : _c.length) - 1 !== i
              ? fullName.concat(', ')
              : fullName;
          }
          fullName = truncate(fullName, 40);
        }
        else {
          fullName = mentee.title;
        }
      }
    }
    else if (account && (isAccountMenteeInMeeting || isGroupMenteeInMeeting)) {
      fullName = `${mentor.firstName} ${mentor.lastName}`;
    }
    const meetingTime = startDate + ' - ' + endDate;
    const displayBreakLine = i < (meetings === null || meetings === void 0 ? void 0 : meetings.length) - 1;
    // TODO @emad: Bunların isimlerini doğrudan sözlükten çekmek lazım. '+ Meet' şeklinde olmasın
    const meetingLocation = ((_d = meeting.location) === null || _d === void 0 ? void 0 : _d.type) === 'microsoftbusiness' ? 'Microsoft Teams' : `${((_f = (_e = meeting.location) === null || _e === void 0 ? void 0 : _e.type) === null || _f === void 0 ? void 0 : _f.charAt(0).toUpperCase()) + ((_h = (_g = meeting.location) === null || _g === void 0 ? void 0 : _g.type) === null || _h === void 0 ? void 0 : _h.slice(1))} ${((_k = (_j = meeting.location) === null || _j === void 0 ? void 0 : _j.type) === null || _k === void 0 ? void 0 : _k.toLowerCase()) === 'zoom' ? '' : strings.meet}`;
    const ownSession = hasMeetingGoal && (meetingGoalConfig === null || meetingGoalConfig === void 0 ? void 0 : meetingGoalConfig.meetingGoals.find(session => session.identifier === meeting.meetingGoalIdentifier));
    return (index.h("div", null, hasMeetingGoal &&
      index.h("div", { class: "meeting-goal-title" }, index.h("h3", null, " ", ownSession === null || ownSession === void 0 ? void 0 :
        ownSession.meetingTitle, " ")), index.h("div", { class: "d-flex justify-content-between align-items-center mt-2" }, index.h("div", { class: "d-flex meeting-data" }, index.h("p", { class: "meeting-date", onClick: () => goToMeetingDetails(meeting) }, " ", index.h("span", null, meetingDate), " "), index.h("div", { class: "flex-column ml-3" }, index.h("div", { class: "full-name" }, index.h("p", null, " ", fullName, " ")), index.h("div", { class: "meeting-time" }, index.h("p", null, " ", meetingTime, " ")), index.h("div", { class: "d-flex align-items-center text-primary" }, meeting.location.type === 'custom' ?
      index.h("p", { class: "custom-address" }, " ", truncate(meeting.location.address, 30), " ")
      :
        index.h("div", { class: "d-flex align-items-center" }, index.h("dvn-icon", { "icon-name": "uil uil-video", scale: "large", size: 20, class: "video-icon" }), index.h("a", { class: "ml-2", target: '_blank', href: meeting.location.address }, " ", meetingLocation, " "))))), index.h("dvn-icon", { onClick: () => goToMeetingDetails(meeting), class: "clickable", "icon-name": "uil uil-angle-right-b", size: 35 })), displayBreakLine &&
      index.h("hr", { class: "break-line" })));
  })));
};
const generateMeetings = (meetings, toggleSeeAllButton) => {
  if (!meetings)
    return [];
  // display only first 3 items
  if (!toggleSeeAllButton) {
    return meetings.slice(0, 3);
  }
  // display all item
  return meetings;
};
const truncate = (text, limit) => {
  if (text.length > limit) {
    return text.substring(0, limit) + '...';
  }
  return text;
};
MentornityUpcomingmeetingsWidget.style = mentornityUpcomingMeetingsWidgetCss;

exports.mentornity_announcements_widget = MentornityAnnouncementsWidget;
exports.mentornity_pair_meeting_summary_widget = MentornityPairsMeetingWidget;
exports.mentornity_past_meetings_widget = MentornityPastMeetingsWidget;
exports.mentornity_program_info_widget = MentornityProgramInfoWidget;
exports.mentornity_upcoming_meetings_widget = MentornityUpcomingmeetingsWidget;
