import Bus, { type UIInteractionDescriptor } from "./bus";


  
  const weatherMap = new Map()
  weatherMap.set("晴", "Sunny")
  weatherMap.set("多云", "Cloudy")
  weatherMap.set("部分多云", "PartlyCloudy")
  weatherMap.set("阴天", "Overcast")
  weatherMap.set("小雨", "LightRain")
  weatherMap.set("中雨", "ModerateRain")
  weatherMap.set("大雨", "HeavyRain")
  weatherMap.set("小雪", "LightSnow")
  weatherMap.set("中雪", "ModerateSnow")
  weatherMap.set("大雪", "HeavySnow")
  weatherMap.set("大雾", "Foggy")
  weatherMap.set("沙尘", "Sand")
  weatherMap.set("霾", "Haze")
  
  /**
   * 设置天气
   * Sunny、Cloudy、PartlyCloudy、Overcast、LightRain、ModerateRain、HeavyRain、LightSnow、ModerateSnow、HeavySnow、Foggy、Sand、Haze
   * 晴、多云、部分多云、阴天、小雨、中雨、大雨、小雪、中雪、大雪、大雾、沙尘、霾
   * @param weather 天气
   */
  export function setWeather(weather = "晴") {
    let wr = "Sunny"
    if (weatherMap.has(weather)) {
      wr = weatherMap.get(weather) || "Sunny"
    }
  
    let descriptor = {
      "command": "SetWeather",
      "data": {
        "weather": wr
      }
    }
    Bus.emit('emitUIInteraction', descriptor)
    console.log("-- 设置天气", JSON.stringify(descriptor));
  }

  export function SetTime(time = "18:00") {
    let descriptor = {
      "command": "SetTime",
      "data": {
      "time": "18:00"
      }
  }
    Bus.emit('emitUIInteraction', descriptor)
    console.log("-- 设置时间", JSON.stringify(descriptor));
  }
  
  // 添加监听器（推荐在应用初始化时执行）
Bus.on('emitUIInteraction',  (descriptor: UIInteractionDescriptor) => {
    console.log('⬇️  收到指令:', descriptor);
    
    // 调试增强 ▼▼▼
    if(descriptor.command  === 'SetWeather') {
      console.groupCollapsed('🏁  天气指令详情');
      console.log(' 指令类型:', descriptor.command); 
      console.log(' 天气参数:', descriptor.data.weather); 
      console.log(' 原始数据:', descriptor);
      console.groupEnd(); 
      
	  // 添加底板响应检测 
	  setTimeout(() => {
		if(!(window as any).UE_ACK) console.warn('⚠️  底板未返回响应');
	  }, 1000);
	}
  });