import { darken } from '../colorHelper';

export const getHeaderNavigationVariables = ({
    navBarPadding,
    navBarBackgroundColor,
    navBarBorderColor,
    navBarLinkSpacing,
    navBarTextColor,
    navBarTextHoverColor
}) => ({
    'header-nav-bar-padding': navBarPadding && `${navBarPadding}px`,
    'header-nav-bg-color': navBarBackgroundColor,
    'header-nav-border-color': navBarBorderColor,
    'header-nav-item-spacing': navBarLinkSpacing && `${navBarLinkSpacing / 2}px`,
    'text-color': navBarTextColor,
    'text-hover-color': navBarTextHoverColor || (navBarTextColor && darken(navBarTextColor, 0.25))
});

export const generateUserLinks = (baseUrl, user, i18n, channelSettings) => {
    if (!baseUrl || !user || !i18n) {
        return null;
    }
    const roles = user?.roles;
    const BILLING_ADMIN_ROLE = Boolean(roles && roles.includes('BILLING_ADMIN'));
    const onlyAdminsCanBuy = Boolean(user?.companyOnlyAdminsCanBuy);
    const enabledWithoutNativeLogin = Boolean(channelSettings && channelSettings?.enabledWithoutNativeLogin);
    const allowNativeLogin = Boolean(channelSettings && channelSettings?.allowNativeLogin);
    const useridpUuid = Boolean(user?.idpUuid);
    const showProfiles = Boolean(channelSettings && channelSettings?.showProfiles);
    const enableMySettingsUnderMyProfile = Boolean(channelSettings?.enableMySettingsUnderMyProfile);

    const hideSettingLink = enableMySettingsUnderMyProfile
    || enabledWithoutNativeLogin
    || (allowNativeLogin && useridpUuid);

    return ([
        showProfiles && {
            label: i18n.profile,
            url: `${baseUrl}/profile/${user.userUuid}`
        },
        (!onlyAdminsCanBuy || BILLING_ADMIN_ROLE) && {
            label: i18n.account,
            url: `${baseUrl}/account/home`
        },
        showProfiles && {
            label: i18n.company,
            url: `${baseUrl}/companies/${user.companyUuid}`
        },
        (!hideSettingLink) && {
            label: i18n.settings,
            url: `${baseUrl}/settings`
        },
        {
            label: i18n.logout,
            url: `${baseUrl}/logout`
        }
    ]);
};

export const getMenu = (menuItems, menuType) => menuItems && menuItems[menuType] && menuItems[menuType].menu;
