import { r as registerInstance, c as createEvent, h, H as Host } from './index-ecdfb761.js';
import { R as ResponsiveSize } from './ui-0156b0ee.js';

const atamaStructuredPairOverviewCss = "atama-structured-pair-overview{display:block}";

const AtamaStructuredPairOverview = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.action = createEvent(this, "action", 7);
    this.meetingsByIdentifiers = {};
  }
  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 { shownMeetingConfig, size, userRefFieldId } = this;
    const showMobileUI = size < ResponsiveSize.Medium;
    return (h(Host, { class: "mb-3" }, showMobileUI
      ? this.renderList()
      : h("dvn-card", { leaned: true, bodyLeaned: true, elevation: 0 }, this.renderList()), h("dvn-dialog", { title: shownMeetingConfig ? shownMeetingConfig.name : undefined, shown: !!shownMeetingConfig, onDismiss: () => this.shownMeetingConfig = undefined }, shownMeetingConfig &&
      h("dvn-markdown", { content: shownMeetingConfig.specifications[userRefFieldId].description }))));
  }
  renderList() {
    const { i18n, meetingsByIdentifiers, pairConfig, size } = this;
    const showMobileUI = size < ResponsiveSize.Medium;
    const Tag = showMobileUI
      ? 'atama-structured-pair-overview-meeting-row-intense'
      : 'atama-structured-pair-overview-meeting-row';
    return pairConfig.structure.meetingConfigs.map((meetingConfig, index) => {
      const meeting = meetingsByIdentifiers[meetingConfig.id];
      const nextMeetingGoal = pairConfig.structure.meetingConfigs.length > index + 2
        && pairConfig.structure.meetingConfigs[index + 1];
      const nextCompleted = nextMeetingGoal && !!meetingsByIdentifiers[nextMeetingGoal.id];
      return (h(Tag, { i18n: i18n, meeting: meeting, meetingConfig: meetingConfig, meetingOrder: index + 1, nextCompleted: nextCompleted, onCreateMeeting: (config) => this.action.emit({
          name: 'create-meeting-with-config-only',
          data: {
            meetingConfig: config,
          }
        }), onShowMeetingDetail: (meetingToShow) => {
          this.action.emit({
            name: 'open-meeting-detail',
            data: {
              meeting: meetingToShow,
            }
          });
        }, onShowMeetingConfigDetail: (config) => {
          this.shownMeetingConfig = config;
        } }));
    });
  }
};
AtamaStructuredPairOverview.style = atamaStructuredPairOverviewCss;

export { AtamaStructuredPairOverview as atama_structured_pair_overview };
