// 环境配置
const config = {
  development: {
    TARO_ACT_HOST: "http://192.168.10.5:3001",
    API_BASE_URL: "/api",
  },
  production: {
    TARO_ACT_HOST: "https://act.yunfanyouxi.com",
    API_BASE_URL: "http://127.0.0.1:8181",
  },
};

// 获取当前环境
const getEnv = () => {
  // 在H5环境中，可以通过location.hostname判断
  if (typeof window !== "undefined") {
    const hostname = window.location.hostname;
    const port = window.location.port;

    // 开发环境判断条件
    if (
      hostname === "localhost" ||
      hostname === "127.0.0.1" ||
      hostname === "192.168.10.5" ||
      (hostname === "localhost" && port === "10086")
    ) {
      return "development";
    }
    return "production";
  }

  // 在小程序环境中，可以通过Taro.getEnv()判断
  try {
    const Taro = require("@tarojs/taro");
    const env = Taro.getEnv();
    return env === "h5" ? "development" : "production";
  } catch (e) {
    return "development"; // 默认开发环境
  }
};

const currentEnv = getEnv();

// 添加调试信息
console.log("当前环境:", currentEnv);
console.log("当前配置:", config[currentEnv]);

export default config[currentEnv];
