"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_tabbarI18n = require("../../utils/tabbar-i18n.js");
const utils_auth = require("../../utils/auth.js");
const modules_Config = require("../../modules/Config.js");
const modules_api_AppServer = require("../../modules/api/AppServer.js");
const _sfc_main = {
  data() {
    return {
      bannerList: [],
      hotList: [],
      aboutUsImage: "",
      // 关于我们图片
      appLogo: "",
      // 应用Logo
      appName: ""
      // 应用名称
    };
  },
  onLoad() {
    this.loadConfig();
    this.loadBanners();
    this.loadHotServices();
  },
  onShow() {
    utils_tabbarI18n.updateTabBarI18n(this);
    this.checkUnreadNotifications();
  },
  methods: {
    /**
     * 加载配置
     */
    async loadConfig() {
      try {
        common_vendor.index.__f__("log", "at pages/index/index.vue:89", "开始加载配置...");
        const config = await modules_Config.Config.getPublicConfig();
        common_vendor.index.__f__("log", "at pages/index/index.vue:91", "获取到的配置:", JSON.stringify(config));
        common_vendor.index.__f__("log", "at pages/index/index.vue:92", "配置类型:", typeof config);
        common_vendor.index.__f__("log", "at pages/index/index.vue:93", "about_us_image值:", config.about_us_image);
        if (config.about_us_image) {
          this.aboutUsImage = modules_Config.Config.getImageUrl(config.about_us_image);
          common_vendor.index.__f__("log", "at pages/index/index.vue:98", "关于我们图片URL:", this.aboutUsImage);
        } else {
          common_vendor.index.__f__("log", "at pages/index/index.vue:100", "配置中没有about_us_image");
        }
        if (config.app_logo) {
          this.appLogo = modules_Config.Config.getImageUrl(config.app_logo);
          common_vendor.index.__f__("log", "at pages/index/index.vue:106", "应用Logo URL:", this.appLogo);
        }
        if (config.app_name) {
          this.appName = config.app_name;
        }
      } catch (error) {
        common_vendor.index.__f__("error", "at pages/index/index.vue:114", "加载配置失败:", error);
      }
    },
    /**
     * 加载Banner列表
     */
    async loadBanners() {
      try {
        common_vendor.index.__f__("log", "at pages/index/index.vue:123", "开始加载Banner...");
        common_vendor.index.__f__("log", "at pages/index/index.vue:124", "API URL:", modules_Config.Config.API_BASE_URL + "/api/v1/home/banners");
        common_vendor.index.request({
          url: modules_Config.Config.API_BASE_URL + "/api/v1/home/banners",
          method: "GET",
          success: (res) => {
            var _a;
            common_vendor.index.__f__("log", "at pages/index/index.vue:130", "Banner请求成功 - res:", res);
            if (res.statusCode === 200 && res.data.code === 0) {
              this.bannerList = res.data.data.map((banner) => ({
                ...banner,
                image_url: modules_Config.Config.getImageUrl(banner.image_url)
              }));
              common_vendor.index.__f__("log", "at pages/index/index.vue:136", "Banner列表:", this.bannerList);
              common_vendor.index.__f__("log", "at pages/index/index.vue:137", "Banner数量:", this.bannerList.length);
            } else {
              common_vendor.index.__f__("log", "at pages/index/index.vue:139", "Banner加载条件不满足");
              common_vendor.index.__f__("log", "at pages/index/index.vue:140", "statusCode:", res.statusCode);
              common_vendor.index.__f__("log", "at pages/index/index.vue:141", "code:", (_a = res.data) == null ? void 0 : _a.code);
            }
          },
          fail: (error) => {
            common_vendor.index.__f__("error", "at pages/index/index.vue:145", "Banner请求失败:", error);
          }
        });
      } catch (error) {
        common_vendor.index.__f__("error", "at pages/index/index.vue:149", "加载Banner失败:", error);
      }
    },
    /**
     * 加载热门服务列表
     */
    async loadHotServices() {
      try {
        common_vendor.index.request({
          url: modules_Config.Config.API_BASE_URL + "/api/v1/home/hot-services",
          method: "GET",
          header: {
            "Accept-Language": this.$i18n.locale || "zh"
          },
          success: (res) => {
            if (res.statusCode === 200 && res.data.code === 0) {
              this.hotList = res.data.data.map((service) => ({
                ...service,
                image_url: service.image_url ? modules_Config.Config.getImageUrl(service.image_url) : null
              }));
              common_vendor.index.__f__("log", "at pages/index/index.vue:171", "热门服务列表:", this.hotList);
            }
          },
          fail: (error) => {
            common_vendor.index.__f__("error", "at pages/index/index.vue:175", "加载热门服务失败:", error);
          }
        });
      } catch (error) {
        common_vendor.index.__f__("error", "at pages/index/index.vue:179", "加载热门服务失败:", error);
      }
    },
    /**
     * 图片加载成功
     */
    handleImageLoad(e) {
      common_vendor.index.__f__("log", "at pages/index/index.vue:187", "图片加载成功:", e);
    },
    /**
     * 图片加载失败 - 清空图片URL显示占位符
     */
    handleImageError(e) {
      common_vendor.index.__f__("error", "at pages/index/index.vue:194", "图片加载失败:", e);
      common_vendor.index.__f__("error", "at pages/index/index.vue:195", "图片URL:", this.aboutUsImage);
      this.aboutUsImage = "";
    },
    /**
     * 检查未读通知并更新TabBar红点
     */
    async checkUnreadNotifications() {
      if (!utils_auth.isLoggedIn()) {
        common_vendor.index.removeTabBarBadge({ index: 2 });
        return;
      }
      try {
        const appserver = new modules_api_AppServer.AppServer();
        const response = await appserver.GetNotificationUnreadCount();
        if (response.code === 0 && response.data) {
          const unreadCount = response.data.all || 0;
          if (unreadCount > 0) {
            common_vendor.index.setTabBarBadge({
              index: 2,
              text: unreadCount > 99 ? "99+" : String(unreadCount)
            });
          } else {
            common_vendor.index.removeTabBarBadge({ index: 2 });
          }
        }
      } catch (error) {
        common_vendor.index.__f__("error", "at pages/index/index.vue:224", "检查未读通知失败:", error);
      }
    },
    /**
     * 跳转到详情页（需要登录）
     */
    toDetails(item) {
      if (!utils_auth.requireAuth(true)) {
        return;
      }
      common_vendor.index.navigateTo({
        url: "/pages/index/reserve-details-page?id=" + item.id + "&title=" + encodeURIComponent(item.name) + "&serviceType=" + encodeURIComponent(item.service_type)
      });
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: $data.bannerList.length > 0
  }, $data.bannerList.length > 0 ? {
    b: common_vendor.f($data.bannerList, (item, index, i0) => {
      return {
        a: item.image_url,
        b: item.id
      };
    })
  } : {}, {
    c: common_vendor.t(_ctx.$t("home.hotServices")),
    d: common_vendor.f($data.hotList, (item, index, i0) => {
      return {
        a: item.image_url || "/static/placeholder.png",
        b: common_vendor.t(item.name),
        c: item.id,
        d: common_vendor.o(($event) => $options.toDetails(item), item.id)
      };
    }),
    e: common_vendor.t(_ctx.$t("home.aboutMe")),
    f: $data.aboutUsImage
  }, $data.aboutUsImage ? {
    g: $data.aboutUsImage,
    h: common_vendor.o((...args) => $options.handleImageError && $options.handleImageError(...args)),
    i: common_vendor.o((...args) => $options.handleImageLoad && $options.handleImageLoad(...args))
  } : {
    j: common_vendor.t(_ctx.$t("home.aboutMe"))
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/index.js.map
