'use strict';

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

const index = require('./index-ce58ddc5.js');
const ui = require('./ui-2403d3b4.js');
const dataModel = require('./data-model-9afb7f54.js');
const itemFetchState = require('./item-fetch-state-0a5bc42a.js');
const pairConfig = require('./pair-config-278a2924.js');
const string = require('./string-de672b69.js');
const User = require('./User-e15e0b6d.js');
const i18n = require('./i18n-592bf756.js');
require('./table-config-73a193be.js');
require('./FieldModelGenerator-1af8e5c3.js');
require('./reference-field-dda66f2e.js');
require('./BaseField-d019ade6.js');
require('./index-f92537c9.js');
require('./index-7e3bc620.js');
require('./date-25b104f6.js');
require('./index-9ea6c7b1.js');
require('./index-93271b8c.js');
require('./index-29b7cb16.js');
require('./index-792d710c.js');
require('./i18n-a8cc9ef1.js');
require('./i18n-0bdc9383.js');

function buildSummaryCardViewConfig(view) {
  var _a, _b;
  return Object.assign(Object.assign({}, (_a = view.ui.main) === null || _a === void 0 ? void 0 : _a.infoSummaryCardViewConfig), { footer: {
      actions: [
        {
          ui: {
            label: ((_b = view.ui.i18n) === null || _b === void 0 ? void 0 : _b.seeMore) || 'See More',
            name: 'open-member-detail-view',
            view: 'flat'
          }
        }
      ]
    } });
}
let DvnAppViewAtamaMemberPairDetailView = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.action = index.createEvent(this, "action", 7);
    this.item = itemFetchState.ItemFetchState.init();
    this.showInfoDetailDialog = false;
    this.showEndPairConfirmationDialog = false;
    this.onSizeChange = (size) => {
      this.size = size;
    };
  }
  onAction(event) {
    const action = event.detail;
    if (action.name === 'open-member-detail-view') {
      event.preventDefault();
      this.showInfoDetailDialog = true;
    }
    if (action.name === 'create-meeting-with-config-only') {
      event.preventDefault();
      // the children who fires this event doesn't have the item detail
      // catch the event, add the item details and fire the same event
      this.action.emit({
        name: 'create-meeting',
        data: {
          meetingConfig: event.detail.data.meetingConfig,
          item: this.item.data,
        }
      });
    }
  }
  fetchMembershipConfigOfMemberToShow() {
    const { notifier, view: { ui: { i18n }, table } } = this;
    const { memberToViewRefFieldId } = this.params;
    const pairConfig$1 = table;
    this.apiUye.getMembershipConfigWithName(pairConfig.getPairConfigMemberCollection(pairConfig$1, memberToViewRefFieldId)).then(response => {
      this.membershipConfigToShow = response;
      this.fetchItem();
    }, error => notifier.alert((i18n === null || i18n === void 0 ? void 0 : i18n.fetchConfigurationError) || 'Getting configuration failed.', error.status));
  }
  fetchItem(ignoreError = false) {
    const { membershipConfigToShow, item, view: { ui: { i18n } } } = this;
    if (item.isPending || (item.error && !ignoreError)) {
      return;
    }
    const { notifier, view: { table } } = this;
    const pairConfig$1 = table;
    const { memberToViewRefFieldId, memberToViewRefFieldValue } = this.params;
    this.item = item.beforeFetch();
    this.apiData.get(pairConfig.getPairConfigMemberCollection(pairConfig$1, memberToViewRefFieldId), memberToViewRefFieldValue, {
      fields: membershipConfigToShow.fields,
    }).then(response => this.item = item.afterFetch(response), error => {
      this.item = item.afterFetchError(error);
      notifier.alert((i18n === null || i18n === void 0 ? void 0 : i18n.fetchItemError) || 'Getting item failed.', error.status);
    });
  }
  completePair() {
    this.apiAtama.endPair('', '', this.params.pairId).then(() => {
      this.action.emit({
        type: 'navigation',
        direction: 'forward',
        resetHistory: true,
        viewId: this.params.viewIdToNavigateOnEndPair,
      });
    });
  }
  async componentWillLoad() {
    this.strings = await this.apiSozluk.getContent(this.view.i18nEntryId, i18n.takvimAvailableTimePickerI18nDefault);
  }
  componentDidLoad() {
    this.fetchMembershipConfigOfMemberToShow();
    this.uiHelper = new ui.ResponsiveUIHelper(this.el, this.onSizeChange);
  }
  render() {
    var _a, _b, _c, _d, _e;
    const { membershipConfigToShow, item, size, strings, userSettings, view: { ui: { i18n } } } = this;
    const showMobileUI = size < ui.ResponsiveSize.Medium;
    if (!item.data || !membershipConfigToShow) {
      return (index.h(index.Host, { class: "d-flex justify-content-center pt-3 mt-3" }, index.h("dvn-progress", { indefinite: true })));
    }
    const { view } = this;
    const pairConfig = view.table;
    const calendarConfigId = (_a = pairConfig.calendarConfig) === null || _a === void 0 ? void 0 : _a._id;
    const membership = item.data;
    // TODO add this to config because we need this feature for groups as well
    const userToView = dataModel.getDataModelField(membership, 'user');
    const infoSummaryCardViewConfig = (_b = view.ui.main) === null || _b === void 0 ? void 0 : _b.infoSummaryCardViewConfig;
    const canCompletePairProcess = (_c = pairConfig.actionPermissions[this.params.userRefFieldId]) === null || _c === void 0 ? void 0 : _c.completePair;
    return (index.h(index.Host, { class: "d-block mt-3 pt-3" }, index.h("div", { class: "row" }, index.h("div", { class: {
        'col-sm-12 col-md-9': !showMobileUI,
        'col-sm-12': showMobileUI,
      } }, index.h("dvn-card", { elevation: 0, leaned: true }, index.h("div", { class: "d-flex align-items-center" }, index.h("dvn-image", { src: userToView.imageUrl, shape: "circle", size: 48, text: User.getUserInitials(userToView) }), index.h("div", { class: "d-flex flex-column ml-2" }, index.h("b", { class: "mb-1" }, User.getUserFullName(userToView)), index.h("small", null, string.capitalize((i18n === null || i18n === void 0 ? void 0 : i18n.roleName) || membershipConfigToShow.roleName)))), (showMobileUI && this.params.showSendMessageButton) &&
      index.h("dvn-card-footer", { slot: "footer", alignRight: true }, this.params.showSendMessageButton &&
        index.h("dvn-icon-button", { iconName: "uil uil-envelope", onClick: () => this.action.emit({
            name: 'send-message',
            data: {
              item: item.data,
            }
          }), view: "outline" }))), infoSummaryCardViewConfig &&
      index.h("div", { class: "mt-3" }, index.h("div", { class: "ml-2 mb-2" }, index.h("small", null, index.h("b", null, (i18n === null || i18n === void 0 ? void 0 : i18n.info) || 'INFO'))), index.h("dvn-card-view", { config: buildSummaryCardViewConfig(view), fields: membershipConfigToShow.fields, item: membership, leaned: true }), index.h("dvn-dialog", { shown: this.showInfoDetailDialog, onDismiss: () => this.showInfoDetailDialog = false, raw: true }, index.h("dvn-card-view", { config: this.view.ui.main.infoDetailCardViewConfig, fields: membershipConfigToShow.fields, item: membership }))), calendarConfigId &&
      index.h("div", { class: "mt-3" }, index.h("div", { class: "ml-2 mb-2" }, index.h("small", null, index.h("b", null, (i18n === null || i18n === void 0 ? void 0 : i18n.getMeeting) || 'GET MEETING'))), index.h("takvim-available-time-picker", { apiTakvim: this.apiTakvim, userId: this.user._id, membershipConfigId: this.membership.config._id, userSettings: this.userSettings, viewedUserId: this.item.data.user._id, viewedUserMembershipConfigId: membershipConfigToShow._id, calendarConfigId: calendarConfigId, meetingTypes: (_d = pairConfig.structure) === null || _d === void 0 ? void 0 : _d.meetingConfigs.map(mc => ({
          id: mc.id,
          name: mc.name,
          maxCount: mc.meetingCount,
        })), onCreateMeeting: () => {
          var _a, _b, _c, _d;
          (_b = (_a = this.el.querySelector(`takvim-meeting-list`)) === null || _a === void 0 ? void 0 : _a.invalidate) === null || _b === void 0 ? void 0 : _b.call(_a);
          (_d = (_c = this.el.querySelector(`atama-structured-pair-overview`)) === null || _c === void 0 ? void 0 : _c.invalidate) === null || _d === void 0 ? void 0 : _d.call(_c);
        }, strings: strings, weekStartDay: userSettings.weekStartDay })), pairConfig.structure
      ? index.h("div", { class: "mt-3" }, index.h("div", { class: "ml-2 mb-2" }, index.h("small", null, index.h("b", null, (i18n === null || i18n === void 0 ? void 0 : i18n.meetings) || 'MEETINGS'))), index.h("atama-structured-pair-overview", { i18n: i18n, apiAtama: this.apiAtama, apiTakvim: this.apiTakvim, pairConfig: pairConfig, userRefFieldId: this.params.userRefFieldId, size: size, sessionUserId: this.user._id, userId: this.item.data.user._id }))
      : index.h("div", { class: "mt-3" }, index.h("div", { class: "ml-2 mb-2" }, index.h("small", null, index.h("b", null, (i18n === null || i18n === void 0 ? void 0 : i18n.meetings) || 'MEETINGS'))), index.h("takvim-meeting-list", { apiTakvim: this.apiTakvim, calendarConfigId: (_e = pairConfig.calendarConfig) === null || _e === void 0 ? void 0 : _e._id, guestIDs: [this.item.data.user._id, this.user._id], userSettings: this.userSettings }))), !showMobileUI &&
      index.h("div", { class: "col-sm-12 col-md-3" }, index.h("div", null, this.params.showSendMessageButton &&
        index.h("dvn-button", { leaned: true, onClick: () => this.action.emit({
            name: 'send-message',
            data: {
              item: item.data,
            }
          }), tint: "primary", view: "flat" }, (i18n === null || i18n === void 0 ? void 0 : i18n.sendMessage) || 'Send Message')), canCompletePairProcess &&
        index.h("div", null, index.h("dvn-button", { leaned: true, onClick: () => {
            this.showEndPairConfirmationDialog = true;
          }, tint: "primary", view: "flat" }, (i18n === null || i18n === void 0 ? void 0 : i18n.endPair) || 'Finish This Process'), index.h("dvn-dialog", { title: (i18n === null || i18n === void 0 ? void 0 : i18n.endPairConfirmationTitle) || 'Are you sure to end the process?', shown: this.showEndPairConfirmationDialog, onDismiss: () => this.showEndPairConfirmationDialog = false }, (i18n === null || i18n === void 0 ? void 0 : i18n.endPairConfirmationDescription) || 'This action removes the pair from your account. You will not be able to schedule meetings with this person.', index.h("div", { slot: "actions" }, index.h("dvn-button", { tint: "primary", view: "flat", onClick: () => this.showEndPairConfirmationDialog = false }, (i18n === null || i18n === void 0 ? void 0 : i18n.cancel) || 'Cancel'), index.h("dvn-button", { tint: "danger", view: "flat", onClick: () => this.completePair() }, (i18n === null || i18n === void 0 ? void 0 : i18n.endPairConfirmationFinishPair) || 'Finish the Process'))))))));
  }
  get el() { return index.getElement(this); }
};

exports.dvn_app_view_atama_member_pair_detail_view = DvnAppViewAtamaMemberPairDetailView;
