import { APP_BASE_HREF } from "@angular/common";
import { FactoryProvider } from "@angular/core";

export function resolveBaseHrefFromUrl() {
    const matches = window.location.href.match(/\/\w{2}-\w{2}/gi);
    if (matches) return matches[0];
    // country-language
    return '/ru-ru';
}

export const baseHrefProvider: FactoryProvider = {
    provide: APP_BASE_HREF,
    useFactory: resolveBaseHrefFromUrl,
};