/**
 * Languages API client
 * @since 1.2.0
 */

import { apiClient } from './client'

export interface LanguageConfig {
  enabled: string[]
  current: string
  is_rtl: boolean
  labels: Record<string, string>
}

interface WPResponse<T> {
  success: boolean
  data: T
}

export const languagesApi = {
  async getConfig(): Promise<LanguageConfig> {
    const res = await apiClient.get<WPResponse<LanguageConfig>>('languages')
    return res.data ?? res as unknown as LanguageConfig
  },

  async setCurrent(language: string): Promise<{ language: string; is_rtl: boolean }> {
    const res = await apiClient.post<WPResponse<{ language: string; is_rtl: boolean }>>('languages/current', { language })
    return res.data ?? res as unknown as { language: string; is_rtl: boolean }
  },
}
