import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-b7735e0d.js';
import { a as ResponsiveSize, R as ResponsiveUIHelper } from './ui-c7f31f6f.js';
import './index-774783ee.js';
import './index-7b119e61.js';
import { R as ReferenceField } from './reference-field-0e7cd534.js';
import { T as TextField } from './index-403101cb.js';
import { V as ViewPlacement } from './app-config-5d14e7bf.js';
import { t as takvimMeetingListI18nDefault } from './i18n-f54b4247.js';
import { D as DateField } from './date-ce777316.js';
import { a as AttachmentField } from './attachment-32decf79.js';
import './BaseField-461b6d0c.js';
import './data-model-f7ccf826.js';

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

let 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;

const takvimMeetingListCss = "takvim-meeting-list{display:block}takvim-meeting-list .progress-container{display:-ms-flexbox;display:flex;height:100%;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;padding-bottom:1rem}";

const collectionFields = [
  new DateField('startDate', 'Date').setDateFormat('DD MMM YYYY'),
  new ReferenceField('guests', 'Guests', 'name', 'imageUrl', 'users', [
    new AttachmentField('imageUrl'),
    new TextField('name', ''),
  ], false)
];
const listViewConfig = (userSettings, showMobileUI) => {
  const { timeFormat, dateFormat } = userSettings;
  const hourFormat = timeFormat === '12-hour' ? 'hh:mm A' : 'HH:mm';
  const formattedDate = showMobileUI ? (dateFormat === 'DD/MM/YYYY' ? 'DD MMM' : 'MMM DD') : (dateFormat === 'DD/MM/YYYY' ? 'DD MMMM YYYY, ddd' : 'MMMM DD YYYY, ddd');
  const fields = [
    {
      fieldId: 'startDate',
      fieldDisplay: new DateField('startDate', 'Date').setDateFormat(formattedDate),
      timeZone: userSettings.timeZone,
    },
    {
      fieldId: 'startHour',
      fieldDisplay: new DateField('startDate', 'Start').setDateFormat(hourFormat),
      timeZone: userSettings.timeZone,
    },
    {
      fieldId: 'endHour',
      fieldDisplay: new DateField('endDate', 'End').setDateFormat(hourFormat),
      timeZone: userSettings.timeZone,
    },
  ];
  if (!showMobileUI) {
    fields.push({ fieldId: 'guests', imageShape: 'circle' });
  }
  return {
    hideHeader: true,
    actionsWidth: showMobileUI ? 48 : 64,
    actions: [
      {
        ui: {
          name: 'open-meeting-detail-from-meeting-list',
          label: 'Open',
          buttonType: 'icon-button',
          iconName: 'uil uil-arrow-right',
          view: 'flat',
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: ViewPlacement.Page,
          viewId: 'meeting-page',
          params: {
            conversionConfig: {
              'item._id': 'meetingId',
            },
          }
        }
      },
    ],
    fields,
    columns: {
      'startHour': showMobileUI ? { weight: 1 } : { width: 100 },
      'guests': {
        width: 100
      }
    }
  };
};
let TakvimMeetingList = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.action = createEvent(this, "action", 7);
    this.isProgressing = true;
    this.strings = takvimMeetingListI18nDefault;
    this.onSizeChange = (size) => {
      this.size = size;
    };
  }
  componentWillLoad() {
    this.uiHelper = new ResponsiveUIHelper(this.el, this.onSizeChange);
    this.size = ResponsiveUIHelper.getSize(this.el.parentElement.clientWidth);
  }
  componentDidLoad() {
    this.fetchMeetings();
  }
  async invalidate(_event) {
    this.meetings = undefined;
    this.error = undefined;
    this.fetchMeetings();
  }
  ;
  async fetchMeetings() {
    const { calendarConfigId, guestIDs } = this;
    const meetings = await this.apiTakvim.getMeetingsOfUser(calendarConfigId, guestIDs).catch(e => {
      this.error = e;
    }).finally(() => this.isProgressing = false);
    if (!meetings)
      return;
    this.meetings = meetings.results;
  }
  render() {
    const { meetings, size, strings, userSettings } = this;
    if (!meetings) {
      return (h(Host, { class: "mb-3" }, h("div", { class: "progress-container" }, h("dvn-progress", { indefinite: true, tint: "primary" }))));
    }
    const showMobileUI = size < ResponsiveSize.Small;
    return (h(Host, { class: "mb-3" }, meetings.length === 0 &&
      h("dvn-card", { elevation: 0, leaned: true }, h("div", { class: "empty-message-container text-centered" }, strings.noItemInList)), h("dvn-list-view-table", { config: listViewConfig(userSettings, showMobileUI), fields: collectionFields, items: meetings, isEndReached: true, isProgressing: this.isProgressing, error: this.error ? strings.fetchingListFailed : undefined, onRetry: () => this.fetchMeetings(), params: {} })));
  }
  get el() { return getElement(this); }
};
TakvimMeetingList.style = takvimMeetingListCss;

export { AtamaStructuredPairOverview as atama_structured_pair_overview, TakvimMeetingList as takvim_meeting_list };
