import { r as registerInstance, c as createEvent, h, H as Host } from './index-acdc1ac0.js';
import { a as ResponsiveSize } from './ui-f4196fad.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 = {};
  }
  componentDidLoad() {
    this.fetchMeetings();
  }
  async fetchMeetings() {
    const response = await this.apiAtama.getMeetingsOfUser('', '', '', '');
    const meetingsByIdentifiers = {};
    response.results.forEach(meeting => {
      meetingsByIdentifiers[meeting.meetingGoalIdentifier] = 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;
        }, showCreateMeetingButton: this.showCreateMeetingButton }));
    });
  }
};
AtamaStructuredPairOverview.style = atamaStructuredPairOverviewCss;

export { AtamaStructuredPairOverview as atama_structured_pair_overview };
