/**
* @external MenuDefinition
* @external UserLinksDefinition
*/
import mustache from 'mustache';
import { menuTemplate } from './Menu.stories.data';
import userLinksTemplateLegacy from '!!raw-loader!../includes/templates/legacy/UserLinks.mustache';
import userLinksTemplate from '!!raw-loader!../includes/templates/UserLinks.mustache';
import userLinksMoreTemplate from '!!raw-loader!../includes/templates/UserLinks__more.mustache';
import { helperClassName, helperMakeMenuData } from './utils';
/**
* @type {MenuDefinition}
*/
const loggedOut = helperMakeMenuData(
'personal',
`
Not logged inTalkContributionsCreate accountLog in`,
helperClassName( 'vector-user-menu-legacy' )
);
const ECHO_ITEMS = `Alerts (0)Notices (3)`;
const USERNAME_ITEM = `WikiUser`;
const REST_ITEMS = `TalkSandboxPreferencesBetaWatchlistContributions`;
const LOGOUT_ITEM = `Log out`;
const ULS_LANGUAGE_SELECTOR = 'English';
const USER_LINKS_ITEMS = `
Talk
Sandbox
Preferences
Watchlist
Contributions
`;
const ANON_USER_LINKS_ITEMS = `
Talk
Contributions
`;
/**
* @type {MenuDefinition}
*/
const loggedInWithEcho = helperMakeMenuData(
'personal',
`${USERNAME_ITEM}${ECHO_ITEMS}${REST_ITEMS}${LOGOUT_ITEM}`,
helperClassName( 'vector-user-menu-legacy' )
);
/**
* @type {MenuDefinition}
*/
const loggedInWithULS = helperMakeMenuData(
'personal',
`${ULS_LANGUAGE_SELECTOR}${USERNAME_ITEM}${ECHO_ITEMS}${REST_ITEMS}${LOGOUT_ITEM}`,
helperClassName( 'vector-user-menu-legacy' )
);
/**
* @type {Object.}
*/
const PERSONAL_MENU_TEMPLATE_DATA = {
loggedOut,
loggedInWithEcho,
loggedInWithULS
};
const additionalUserMoreData = {
class: 'vector-menu vector-user-menu-more',
"heading-class": 'vector-menu-heading',
"is-dropdown": false
};
const userMoreHtmlItems = ( isAnon = true ) => mustache.render( userLinksMoreTemplate, {
'is-anon': isAnon,
'html-create-account': `Create account`,
'data-user-page': helperMakeMenuData( 'user-page', USERNAME_ITEM ),
'data-notifications': helperMakeMenuData( 'notifications', ECHO_ITEMS )
} );
const loggedInData = {
class: 'vector-user-menu vector-menu-dropdown vector-user-menu-logged-in',
'heading-class': 'mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-userAvatar',
'is-anon': false,
'html-after-portal': `
`,
'is-dropdown': true
};
const loggedOutData = {
class: 'vector-user-menu vector-menu-dropdown vector-user-menu-logged-out',
'heading-class': 'mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-ellipsis',
'is-anon': true,
'html-before-portal': `
`,
'is-dropdown': true
};
/**
* @type {UserLinksDefinition}
*/
const USER_LINKS_LOGGED_IN_TEMPLATE_DATA = {
'data-user-more': helperMakeMenuData( 'personal-more', userMoreHtmlItems( false ), additionalUserMoreData ),
'data-user-menu': helperMakeMenuData( 'new-personal', USER_LINKS_ITEMS, loggedInData )
};
/**
* @type {UserLinksDefinition}
*/
const USER_LINKS_LOGGED_OUT_TEMPLATE_DATA = {
'data-user-more': helperMakeMenuData( 'personal-more', userMoreHtmlItems( true ), additionalUserMoreData ),
'data-user-menu': helperMakeMenuData( 'new-personal', ANON_USER_LINKS_ITEMS, loggedOutData )
};
export {
PERSONAL_MENU_TEMPLATE_DATA,
USER_LINKS_LOGGED_IN_TEMPLATE_DATA,
USER_LINKS_LOGGED_OUT_TEMPLATE_DATA,
menuTemplate,
userLinksTemplateLegacy,
userLinksTemplate
};