"use strict";
const common_vendor = require("../../common/vendor.js");
const store_modules_user = require("../../store/modules/user.js");
if (!Math) {
  (Icon + LoginPopup + Tabbar)();
}
const Icon = () => "../../components/icon/index.js";
const Tabbar = () => "../../components/tabbar/index.js";
const LoginPopup = () => "../../components/login/LoginPopup.js";
const _sfc_main = {
  __name: "index",
  setup(__props) {
    const userStore = store_modules_user.useUserStore();
    const hasNewMessage = common_vendor.ref(false);
    const currentStudentIndex = common_vendor.ref(0);
    const isLogin = common_vendor.ref(false);
    const studentIds = common_vendor.ref([]);
    const students = common_vendor.ref([
      {
        id: 0,
        name: "请先登录",
        className: "请先登录",
        avatar: "/static/logo.png"
      }
    ]);
    const goXuncha = () => {
      if (!checkLogin()) {
        pleaseLogin();
        return;
      }
      common_vendor.index.navigateTo({
        url: "/pages/xuncha/mp_excelRcXcdjl_edit"
      });
    };
    const checkLogin = () => {
      const userInfo = common_vendor.index.getStorageSync("userInfo");
      common_vendor.index.__f__("log", "at pages/index/index.vue:136", "userInfo", userInfo);
      if (!userInfo || !userInfo.yhsbToken) {
        return false;
      }
      return true;
    };
    const pleaseLogin = () => {
      common_vendor.index.showToast({
        title: "请先登录",
        icon: "none"
      });
      userStore.showLoginPopup();
    };
    const onSwiperChange = (e) => {
      currentStudentIndex.value = e.detail.current;
    };
    const onSwiperClick = (studentId) => {
      if (studentId == 0) {
        pleaseLogin();
      }
    };
    const goToInOut = () => {
      if (checkLogin()) {
        const currentStudentId = students.value[currentStudentIndex.value].id;
        const index = studentIds.value.indexOf(currentStudentId);
        if (index !== -1) {
          this.studentIds.splice(index, 1);
        }
        common_vendor.index.navigateTo({
          url: "/pages/parent/in-out?role=parent&studentId=" + students.value[currentStudentIndex.value].id
        });
      } else {
        pleaseLogin();
      }
    };
    const goToMessage = () => {
      if (checkLogin()) {
        common_vendor.index.navigateTo({
          url: "/pages/parent/message?role=parent"
        });
      } else {
        pleaseLogin();
      }
    };
    const goToBzrDm = () => {
      if (checkLogin()) {
        common_vendor.index.navigateTo({
          url: "/pages/kqjl/kqjl_bzrDm_list"
        });
      } else {
        pleaseLogin();
      }
    };
    const goToXfjl = () => {
      if (checkLogin()) {
        common_vendor.index.navigateTo({
          url: "/pages/xfjl/index"
        });
      } else {
        pleaseLogin();
      }
    };
    const hasNewRecord = common_vendor.computed(() => {
      var _a;
      const currentStudentId = (_a = students[currentStudentIndex.value]) == null ? void 0 : _a.id;
      if (!currentStudentId)
        return false;
      return this.studentIds.includes(currentStudentId);
    });
    const handleInit = (data) => {
      common_vendor.index.__f__("log", "at pages/index/index.vue:309", "handleInit", data);
      studentIds.value = data.studentIds || [];
    };
    const handleNewMessage = (data) => {
      common_vendor.index.__f__("log", "at pages/index/index.vue:313", "handleNewMessage", data);
      if (!studentIds.value.includes(data.studentId)) {
        studentIds.value.push(data.studentId);
      }
    };
    const handleNewRecord = (data) => {
      common_vendor.index.__f__("log", "at pages/index/index.vue:319", "handleNewRecord", data);
    };
    const handLogin = (data) => {
      isLogin.value = true;
      common_vendor.index.$on("init", handleInit);
      common_vendor.index.$on("newMessage", handleNewMessage);
      common_vendor.index.$on("newRecord", handleNewRecord);
      students.value[0] = {
        id: 1,
        name: "已登录",
        className: "已登录",
        avatar: "/static/logo.png"
      };
    };
    common_vendor.onLoad(async () => {
      common_vendor.index.$on("login", handLogin);
      if (checkLogin()) {
        handLogin();
      } else {
        isLogin.value = false;
      }
    });
    common_vendor.onUnload(async () => {
      common_vendor.index.$off("newMessage", handleNewMessage);
      common_vendor.index.$off("newRecord", handleNewRecord);
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: students.value && students.value.length > 0
      }, students.value && students.value.length > 0 ? {
        b: common_vendor.f(students.value, (student, k0, i0) => {
          return {
            a: student.avatar,
            b: common_vendor.t(student.name),
            c: common_vendor.t(student.className),
            d: student.id,
            e: common_vendor.o(($event) => onSwiperClick(student.id), student.id)
          };
        }),
        c: common_vendor.n(students.value && students.value.length > 1 ? "show-dots" : ""),
        d: students.value && students.value.length > 1,
        e: common_vendor.o(onSwiperChange)
      } : {}, {
        f: common_vendor.p({
          name: "icon-jinchu",
          size: "60",
          color: "#393f51"
        }),
        g: hasNewMessage.value
      }, hasNewMessage.value ? {} : {}, {
        h: common_vendor.o(goToMessage),
        i: common_vendor.p({
          name: "icon-duihuapaopao2",
          size: "60",
          color: "#393f51"
        }),
        j: hasNewRecord.value
      }, hasNewRecord.value ? {} : {}, {
        k: common_vendor.o(goToInOut),
        l: common_vendor.p({
          name: "icon-dianming",
          size: "60",
          color: "#8992ef"
        }),
        m: common_vendor.o(goToBzrDm),
        n: common_vendor.p({
          name: "icon-xuncha",
          size: "60",
          color: "#475fab"
        }),
        o: common_vendor.o(goXuncha),
        p: common_vendor.p({
          name: "icon-xiaofeijilu",
          size: "60",
          color: "#c48c21"
        }),
        q: common_vendor.o(goToXfjl),
        r: isLogin.value
      });
    };
  }
};
wx.createPage(_sfc_main);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/index.js.map
