import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-ecdfb761.js';
import { a as ResponsiveUIHelper, R as ResponsiveSize } from './ui-0156b0ee.js';
import './index-e66e8eca.js';
import './index-61dcd269.js';
import { R as ReferenceField } from './reference-field-a5b414d1.js';
import { T as TextField } from './index-150b6a59.js';
import { V as ViewPlacement } from './app-config-9a584d70.js';
import { t as takvimMeetingListI18nDefault } from './i18n-f54b4247.js';
import { D as DateField } from './date-1bc489bd.js';
import { a as AttachmentField } from './attachment-961dd228.js';
import './FieldGenerator-3ae403b2.js';
import './BaseField-0b01dc2c.js';
import './data-model-88af49fc.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) {
    registerInstance(this, hostRef);
    this.action = createEvent(this, "action", 7);
    this.isProgressing = true;
    this.strings = takvimMeetingListI18nDefault;
    this.scrollToFit = false;
    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: "d-flex flex-grow-1 justify-content-center pt-3" }, h("dvn-progress", { indefinite: true })));
    }
    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: {}, scrollToFit: this.scrollToFit })));
  }
  get el() { return getElement(this); }
};
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: 120
      }
    }
  };
};
TakvimMeetingList.style = takvimMeetingListCss;

export { TakvimMeetingList as takvim_meeting_list };
