'use strict';

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

const index = require('./index-1141a245.js');
const ui = require('./ui-924b3658.js');
require('./index-e751cab0.js');
require('./index-2eea69a0.js');
const referenceField = require('./reference-field-1239b0c3.js');
const index$1 = require('./index-61f9621a.js');
const appConfig = require('./app-config-cb7e78a4.js');
const i18n = require('./i18n-9a433e64.js');
const date = require('./date-a24d7714.js');
const attachment = require('./attachment-b0acc4c1.js');
require('./FieldGenerator-279a646b.js');
require('./BaseField-381327a9.js');
require('./data-model-9afb7f54.js');

const takvimMeetingListCss = "takvim-meeting-list{-ms-flex:1;flex:1;display:-ms-flexbox;display:flex;overflow:hidden}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 TakvimMeetingList = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.action = index.createEvent(this, "action", 7);
    this.isProgressing = true;
    this.strings = i18n.takvimMeetingListI18nDefault;
    this.scrollToFit = false;
    this.onSizeChange = (size) => {
      this.size = size;
    };
  }
  componentWillLoad() {
    this.uiHelper = new ui.ResponsiveUIHelper(this.el, this.onSizeChange);
    this.size = ui.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 (index.h(index.Host, { class: "d-flex flex-grow-1 justify-content-center pt-3" }, index.h("dvn-progress", { indefinite: true })));
    }
    const showMobileUI = size < ui.ResponsiveSize.Small;
    return (index.h(index.Host, { class: "mb-3" }, meetings.length === 0
      ? index.h("dvn-card", { elevation: 0, leaned: true }, index.h("div", { class: "empty-message-container text-centered" }, strings.noItemInList))
      : index.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: {}, scrollToFit: this.scrollToFit })));
  }
  get el() { return index.getElement(this); }
};
const collectionFields = [
  new date.DateField('startDate', 'Date').setDateFormat('DD MMM YYYY'),
  new referenceField.ReferenceField('guests', 'Guests', 'name', 'imageUrl', 'users', [
    new attachment.AttachmentField('imageUrl'),
    new index$1.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 date.DateField('startDate', 'Date').setDateFormat(formattedDate),
      timeZone: userSettings.timeZone,
    },
    {
      fieldId: 'startHour',
      fieldDisplay: new date.DateField('startDate', 'Start').setDateFormat(hourFormat),
      timeZone: userSettings.timeZone,
    },
    {
      fieldId: 'endHour',
      fieldDisplay: new date.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: appConfig.ViewPlacement.Page,
          viewId: 'meeting-page',
          params: {
            conversionConfig: {
              'item._id': 'meetingId',
            },
          }
        }
      },
    ],
    fields,
    columns: {
      'startHour': showMobileUI ? { weight: 1 } : { width: 100 },
      'guests': {
        width: 120
      }
    }
  };
};
TakvimMeetingList.style = takvimMeetingListCss;

exports.takvim_meeting_list = TakvimMeetingList;
