File size: 1,262 Bytes
db983c6
1928d7f
 
 
 
db983c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
export const CHATBOT_CONFIG = {
  name: process.env.NEXT_PUBLIC_CHATBOT_NAME || "EMA",
  caption: process.env.NEXT_PUBLIC_CHATBOT_CAPTION || "Expert Mining Assistant",
  description: process.env.NEXT_PUBLIC_CHATBOT_DESCRIPTION || "Saya EMA, Expert Mining Assistant. Saya siap membantu kamu menganalisis data equipment dan menjawab pertanyaan seputar operasional tambang.",
};

export type ChatbotConfig = typeof CHATBOT_CONFIG;

// Function to load from localStorage with defaults
export const getChatbotConfig = (): ChatbotConfig => {
  if (typeof window === "undefined") return CHATBOT_CONFIG;
  const stored = localStorage.getItem("ema-chatbot-config");
  if (!stored) return CHATBOT_CONFIG;
  try {
    return { ...CHATBOT_CONFIG, ...JSON.parse(stored) };
  } catch {
    return CHATBOT_CONFIG;
  }
};

// Function to save to localStorage
export const saveChatbotConfig = (config: Partial<ChatbotConfig>) => {
  if (typeof window === "undefined") return;
  const current = getChatbotConfig();
  localStorage.setItem("ema-chatbot-config", JSON.stringify({ ...current, ...config }));
};

// Function to reset to defaults
export const resetChatbotConfig = () => {
  if (typeof window === "undefined") return;
  localStorage.removeItem("ema-chatbot-config");
};