//RSVP
const { POST } = require('commons/namespaces/http-util');
const URLUtil = require('commons/utils/url-util').default;

require('community-components/routes/community-rsvp-digest').default.reopen({
model(params) {
const { digest, rsvpResponse } = params;

if (!digest) {
this.notificationService.error(this.communityProtoService.i18n('msg.err.rsvp.invalid.digest'));
this.transitionTo('community-home');
return;
}

if (!rsvpResponse) {
this.notificationService.error(this.communityProtoService.i18n('msg.err.rsvp.response.invalid'));
this.transitionTo('community-home');
return;
}

const digestUrl = URLUtil.constructRsvpDigestUrl(digest, rsvpResponse);

return POST(digestUrl)
.then(() => {
this.notificationService.success(
this.communityProtoService.i18n('msg.rsvp.response.submitted')
);

// Go to community-home, then reload that URL
this.transitionTo('community-home').then(
() => window.location.replace(window.location.href)
);
})
.catch((error) => {
const errorMessage =
error?.errors?.rsvp?.[0] ||
error?.responseJSON?.errors?.rsvp?.[0] ||
this.communityProtoService.i18n('msg.err.rsvp.response.record.failed');

this.notificationService.error(errorMessage);
this.transitionTo('community-home');
});
}
});
//Profile
const EventTypeUtil = require('community-components/utils/event-type-util');
require('community-components/utils/user').default.reopen({
    checkAndShowWalkThroughModal(context) {
const event = this.get('community-proto.event'),
canHideModal = !event.get('isNetworkingAllowed') && !event.get('getConsentViaOnboarding'),
currentUser = event.get('currentUser'),
showModal = (hasLicense) => {};

if (
!event.get('isSitePrivilegedUser') ||
window.location.hash.includes('exhibitor-dashboard') ||
window.location.hash.includes('badges') ||
canHideModal
) {
return;
}

const isWalkThroughModelShown = localStorage.getItem(
`${event.get('id')}-${currentUser.get('userProfile.id')}-walkThrough-shown`
);
if (EventTypeUtil.getProp('isExpoMeetingSupported', event) || currentUser.isBoothMember) {
const canShowModalWithLicence =
EventTypeUtil.getProp('isExpoMeetingSupported', event) &&
currentUser.isBoothMember &&
event.get('planProps.allowExpo');
if (isWalkThroughModelShown) {
this.loadExpoMetaData(event, event.get('currentUser.exhibitorId'));
return;
}
if (canShowModalWithLicence) {
this.loadExpoMetaData(event, event.get('currentUser.exhibitorId'), showModal);
} else {
this.loadExpoMetaData(event, event.get('currentUser.exhibitorId'));
showModal(false);
}
return;
}

if (isWalkThroughModelShown) {
return;
}

return showModal(false);
}
})
