import client from './client';

export interface ThemeConfig {
  primary_color?: string;
  logo_url?: string;
  sidebar_style?: 'light' | 'dark';
  brand_name?: string;
  brand_slogan?: string;
  brand_features?: string;
  brand_copyright?: string;
}

export async function getTheme() {
  const { data } = await client.get<{ success: boolean; data: ThemeConfig }>(
    '/config/themes',
  );
  return data.data;
}

export async function updateTheme(theme: ThemeConfig) {
  const { data } = await client.put<{ success: boolean; data: ThemeConfig }>(
    '/config/themes',
    theme,
  );
  return data.data;
}

export interface BrandConfig {
  brand_name: string;
  brand_slogan: string;
  brand_features: string;
  brand_copyright: string;
}

const BRAND_DEFAULTS: BrandConfig = {
  brand_name: 'HMS 健康管理平台',
  brand_slogan: '新一代健康管理平台',
  brand_features: '患者管理 · 健康监测 · 随访管理 · AI 智能分析',
  brand_copyright: 'HMS 健康管理平台 · ©汕头市智界科技有限公司',
};

export async function getPublicBrand(): Promise<BrandConfig> {
  try {
    const res = await fetch('/api/v1/public/brand');
    const json = await res.json();
    if (json?.success && json?.data) return json.data;
  } catch {}
  return BRAND_DEFAULTS;
}
