import { apiClient } from './client'; import type { AjaxResponse } from '@/types/api.types'; import type { Province, District, Ward, AddressData } from '@/types/address.types'; // Get list of provinces (from PHP data) export const getProvinces = async (): Promise => { // In actual implementation, this might be localized data // For now, we'll make it compatible with the existing structure const response = await apiClient.post>('', { action: 'get_provinces', }); return response.data.data || []; }; // Get districts by province code export const getDistricts = async (provinceCode: string): Promise => { try { const response = await apiClient.post>('', { action: 'coolviad_load_administrative_units', matp: provinceCode, }); return response.data.data || []; } catch (error) { return []; } }; // Get wards by district code export const getWards = async (districtCode: string): Promise => { const response = await apiClient.post>('', { action: 'coolviad_load_administrative_units', maqh: districtCode, }); return response.data.data || []; }; // Get address by phone number export const getAddressByPhone = async ( phone: string, recaptchaToken?: string ): Promise<{ billing: AddressData; district: District[] }> => { const response = await apiClient.post>('', { action: 'get_address_byphone', phone, 'g-recaptcha-response': recaptchaToken || '', }); if (!response.data.success) { throw new Error(response.data.message || 'Failed to get address'); } return response.data.data!; };