// 省市区数据
import provinces from 'china-division/dist/provinces.json';
import cities from 'china-division/dist/cities.json';
import areas from 'china-division/dist/areas.json';

interface RegionItem {
  code: string;
  name: string;
}

// 转换省份数据
const provinceList: RegionItem[] = provinces.map((p: any) => ({
  code: p.code,
  name: p.name,
}));

// 转换城市数据 - 按省份code分组
const cityData: Record<string, RegionItem[]> = {};
cities.forEach((c: any) => {
  const provinceCode = c.provinceCode;
  if (!cityData[provinceCode]) {
    cityData[provinceCode] = [];
  }
  cityData[provinceCode].push({
    code: c.code,
    name: c.name,
  });
});

// 转换区县数据 - 按城市code分组
const districtData: Record<string, RegionItem[]> = {};
areas.forEach((a: any) => {
  const cityCode = a.cityCode;
  if (!districtData[cityCode]) {
    districtData[cityCode] = [];
  }
  districtData[cityCode].push({
    code: a.code,
    name: a.name,
  });
});

export const regionData = {
  provinces: provinceList,
  cities: cityData,
  districts: districtData,
};
