import { id, type WorkpulseLocaleMessages } from "./id";
import { en } from "./en";
import type { WorkpulseFeatureKey } from "../workpulse-permissions";

const FEATURE_PATHS: Record<WorkpulseFeatureKey, string> = {
  dashboard: "/",
  report: "/report",
  calendar: "/calendar",
  team: "/team",
  analytics: "/analytics",
  notifications: "/notifications",
  chat: "/chat"
};

export type WorkpulseLocale = "id" | "en";

export const WORKPULSE_LOCALE_STORAGE_KEY = "workpulse-locale";

export const WORKPULSE_LOCALE_MESSAGES: Record<WorkpulseLocale, WorkpulseLocaleMessages> = {
  id,
  en
};

export type { WorkpulseLocaleMessages };

/** Replace `{key}` placeholders in a message template. */
export function formatLocaleMessage(template: string, vars: Record<string, string | number>): string {
  return template.replace(/\{(\w+)\}/g, (_, key: string) => String(vars[key] ?? ""));
}

/** Label fitur untuk Workspace / permissions — mengikuti locale aktif. */
export function localizedFeatureDefs(locale: WorkpulseLocale) {
  const pack = WORKPULSE_LOCALE_MESSAGES[locale];
  const keys = Object.keys(FEATURE_PATHS) as WorkpulseFeatureKey[];
  return keys.map((key) => ({
    key,
    path: FEATURE_PATHS[key],
    label: pack.features[key].label,
    description: pack.features[key].description
  }));
}
