'use strict';

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

const index = require('./index-1141a245.js');
const ui = require('./ui-924b3658.js');
const calendar = require('./calendar-e4b7baeb.js');
require('./index-b776fc14.js');
require('./_commonjsHelpers-206db00d.js');
require('./moment-7a3433f2.js');

const atamaStructuredPairSessionOverviewCss = "atama-structured-pair-session-overview p,atama-structured-pair-session-overview h3{margin:var(--spacing-unit) 0}atama-structured-pair-session-overview .error-text{color:var(--color-danger)}atama-structured-pair-session-overview .break-line{height:1px;color:var(--color-background-secondary)}atama-structured-pair-session-overview .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}atama-structured-pair-session-overview .border-dashed{border-style:dashed !important;border-width:1px !important}atama-structured-pair-session-overview .meeting-date{display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;background-color:var(--color-background-secondary);font-weight:bold;color:var(--color-text);min-width:65px;max-width:-webkit-min-content;max-width:-moz-min-content;max-width:min-content;min-height:70px;max-height:70px;border-radius:var(--corner-radius);text-align:center}atama-structured-pair-session-overview .meeting-date .day-and-month{font-size:var(--font-size-medium);font-weight:bold;display:-ms-flexbox;display:flex;-ms-flex-preferred-size:min-content;flex-basis:min-content}atama-structured-pair-session-overview .meeting-date .meeting-year{font-weight:100}atama-structured-pair-session-overview .clickable:hover{cursor:pointer;text-decoration:underline}atama-structured-pair-session-overview .font-medium{font-size:var(--font-size-medium)}atama-structured-pair-session-overview .meeting-time{font-size:var(--font-size-medium);color:var(--color-neutral)}atama-structured-pair-session-overview .zero-margin-icon i::before{margin:0}atama-structured-pair-session-overview .custom-address{color:var(--color-text-title)}atama-structured-pair-session-overview h4{margin:0}";

const AtamaStructuredPairSessionOverview = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.action = index.createEvent(this, "action", 7);
    this.meetingsByIdentifiers = {};
    this.renderHasSessionDesign = (meetingGoal, sessionName) => {
      var _a, _b, _c, _d, _e;
      const meetingDayAndMonth = calendar.CalendarUtils.format(new Date(meetingGoal.startDate), 'MMM DD');
      const day = calendar.CalendarUtils.format(new Date(meetingGoal.startDate), 'dddd');
      const directionBetweenDatesInMinutes = getMinutesBetweenDates(new Date(meetingGoal.startDate), new Date(meetingGoal.endDate));
      const startDate = calendar.CalendarUtils.format(new Date(meetingGoal.startDate), `HH:mm ${calendar.CalendarUtils.timeFormat === '12-hour' ? 'A' : ''}`);
      const meetingLocation = ((_a = meetingGoal.location) === null || _a === void 0 ? void 0 : _a.type) === 'microsoftbusiness' ? 'Microsoft Teams' : `${((_c = (_b = meetingGoal.location) === null || _b === void 0 ? void 0 : _b.type) === null || _c === void 0 ? void 0 : _c.charAt(0).toUpperCase()) + ((_e = (_d = meetingGoal.location) === null || _d === void 0 ? void 0 : _d.type) === null || _e === void 0 ? void 0 : _e.slice(1))}`;
      return (index.h("div", { class: "d-flex justify-content-between align-items-center mt-2" }, index.h("div", { class: "d-flex meeting-data" }, index.h("div", { class: "meeting-date clickable", onClick: () => {
          this.action.emit({
            name: 'open-meeting-detail',
            data: {
              meeting: meetingGoal
            }
          });
        } }, index.h("span", { class: "day-and-month" }, meetingDayAndMonth)), index.h("div", { class: "flex-column ml-3" }, index.h("h4", null, sessionName), index.h("div", { class: "meeting-time" }, index.h("p", null, " ", day, " - ", startDate, " - ", directionBetweenDatesInMinutes, " minutes ")), index.h("div", { class: "d-flex align-items-center text-primary" }, meetingGoal.location.type === 'custom' || meetingGoal.location.type === undefined ?
        index.h("p", { class: "custom-address" }, " ", truncate(meetingGoal.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: "zero-margin-icon" }), index.h("a", { class: "ml-2", target: '_blank', href: meetingGoal.location.address }, " ", meetingLocation, " "))))), index.h("dvn-icon", { onClick: () => {
          this.action.emit({
            name: 'open-meeting-detail',
            data: {
              meeting: meetingGoal
            }
          });
        }, class: "clickable", "icon-name": "uil uil-angle-right-b", size: 35 })));
    };
    this.renderSessionEmptyDesign = (emptyGoal) => {
      const showMobileUI = this.size < ui.ResponsiveSize.Medium;
      return (index.h("div", { class: "d-flex align-items-center mt-2" }, index.h("div", { class: "meeting-date" }, index.h("dvn-icon", { iconName: "uil uil-schedule", size: 35 })), index.h("div", { class: `d-flex justify-content-between ${showMobileUI ? 'flex-column' : 'align-items-center'}`, style: { width: showMobileUI ? 'auto' : '100%' } }, index.h("div", { class: "font-medium", style: { marginLeft: '16px' } }, index.h("h4", null, emptyGoal.name), index.h("p", { style: { color: 'var(--color-neutral)' } }, this.i18n.notScheduled)), index.h("div", { class: "d-flex align-items-center clickable", style: { marginLeft: '14px' }, onClick: () => {
          this.shownMeetingConfig = emptyGoal;
        } }, index.h("dvn-icon", { class: "zero-margin-icon mr-1", "icon-name": "uil uil-file-alt", size: showMobileUI ? 20 : 30, scale: "large" }), index.h("p", null, this.i18n.aboutThisSession)))));
    };
  }
  async invalidate(_event) {
    this.fetchMeetings();
  }
  ;
  componentDidLoad() {
    this.fetchMeetings();
  }
  async fetchMeetings() {
    var _a;
    const { pairConfig, userId, sessionUserId } = this;
    const response = await this.apiTakvim.getMeetingsOfUser((_a = pairConfig.calendarConfig) === null || _a === void 0 ? void 0 : _a._id, [sessionUserId, userId]);
    const meetingsByIdentifiers = {};
    response.results.forEach(meeting => {
      meetingsByIdentifiers[meeting.meetingType] = meeting;
    });
    this.meetingsByIdentifiers = meetingsByIdentifiers;
  }
  render() {
    const totalMeetingsGoalLength = this.pairConfig.structure.meetingConfigs.length || 0;
    const hasGoalMeetings = totalMeetingsGoalLength > 0;
    const finishedMeetingsGoalLength = Object.keys(this.meetingsByIdentifiers).length;
    const finishedMeetingsGoalPercent = calculateMeetingsPercent(totalMeetingsGoalLength, finishedMeetingsGoalLength, hasGoalMeetings);
    const meetingGoals = this.pairConfig.structure.meetingConfigs;
    const showMobileUI = this.size < ui.ResponsiveSize.Medium;
    return (index.h(index.Host, { class: "mb-3" }, index.h("dvn-card", { leaned: true, elevation: 0, class: "mb-3" }, index.h("div", { class: `d-flex mb-4 ${showMobileUI ? 'flex-column justify-content-center' : 'justify-content-between align-items-center'}` }, index.h("div", { class: `d-flex align-items-center ${!showMobileUI ? 'justify-content-between' : ''}` }, index.h("dvn-linear-progress", { percent: finishedMeetingsGoalPercent, showPercent: true, tint: "secondary" }), index.h("p", { class: "ml-2", style: { color: 'var(--color-text-secondary)' } }, this.i18n.completed)), index.h("p", null, finishedMeetingsGoalLength, " ", finishedMeetingsGoalLength > 1 ? this.i18n.meetingsScheduled : this.i18n.meetingScheduled)), meetingGoals && meetingGoals.map((goalConfig, i) => {
      var _a;
      const renderCurrentMeetingGoal = this.meetingsByIdentifiers[goalConfig.id];
      const sessionName = (_a = meetingGoals.find(goal => goal.id === goalConfig.id)) === null || _a === void 0 ? void 0 : _a.name;
      const hasMeetingGoal = !!renderCurrentMeetingGoal;
      const displayBreakLine = i < (totalMeetingsGoalLength - 1);
      return (index.h("div", null, hasMeetingGoal ?
        this.renderHasSessionDesign(renderCurrentMeetingGoal, sessionName)
        :
          this.renderSessionEmptyDesign(goalConfig), displayBreakLine && index.h("hr", { class: "break-line" })));
    })), index.h("dvn-dialog", { title: this.shownMeetingConfig ? this.shownMeetingConfig.name : undefined, shown: !!this.shownMeetingConfig, onDismiss: () => this.shownMeetingConfig = undefined }, this.shownMeetingConfig &&
      index.h("dvn-markdown", { content: this.shownMeetingConfig.specifications[this.userRefFieldId].description }))));
  }
};
const truncate = (text, limit) => {
  if (text.length > limit) {
    return text.substring(0, limit) + '...';
  }
  return text;
};
const calculateMeetingsPercent = (meetingsGoalLength, finishedMeetingsGoalLength, hasGoalMeetings) => {
  if (!hasGoalMeetings) {
    return '0';
  }
  const result = Math.floor((finishedMeetingsGoalLength / meetingsGoalLength) * 100).toString();
  return result;
};
const getMinutesBetweenDates = (startDate, endDate) => {
  const diff = endDate.getTime() - startDate.getTime();
  return Math.round(diff / 60000);
};
AtamaStructuredPairSessionOverview.style = atamaStructuredPairSessionOverviewCss;

exports.atama_structured_pair_session_overview = AtamaStructuredPairSessionOverview;
