"use strict";
const common_vendor = require("../../../common/vendor.js");
if (!Math) {
  StudentCard();
}
const StudentCard = () => "./StudentCard.js";
const CARD_WIDTH = 200;
const CARD_HEIGHT = 280;
const CARD_GAP = 12;
const _sfc_main = {
  __name: "SeatLayout",
  props: {
    students: {
      type: Array,
      default: () => []
    },
    layout: {
      type: Object,
      default: () => ({ rows: 20, cols: 10 })
    },
    mode: {
      type: String,
      default: "overview"
      // 'overview' | 'attendance'
    }
  },
  emits: ["modeChange", "statusChange", "studentClick"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const lastTap = common_vendor.ref(0);
    const touchStartTime = common_vendor.ref(0);
    const touchStartPos = common_vendor.ref({ x: 0, y: 0 });
    const scrollTop = common_vendor.ref(0);
    const scrollLeft = common_vendor.ref(0);
    common_vendor.ref(null);
    const layoutStyle = common_vendor.computed(() => {
      const totalWidthRpx = props.layout.cols * (CARD_WIDTH + CARD_GAP) - CARD_GAP;
      const totalHeightRpx = props.layout.rows * (CARD_HEIGHT + CARD_GAP) - CARD_GAP;
      common_vendor.index.__f__("log", "at pages/kqjl/components/SeatLayout.vue:115", "SeatLayout 计算样式:", {
        mode: props.mode,
        students: props.students.length,
        layout: props.layout,
        totalWidthRpx,
        totalHeightRpx
      });
      if (props.mode === "overview" || props.mode === "overview-simple") {
        const systemInfo = common_vendor.index.getSystemInfoSync();
        const screenWidthPx = systemInfo.windowWidth;
        const screenWidthRpx = screenWidthPx * 2;
        const targetWidthRpx = screenWidthRpx * 0.9;
        const scale = targetWidthRpx / totalWidthRpx;
        return {
          transform: `scale(${scale})`,
          transformOrigin: "top left",
          width: `${totalWidthRpx}rpx`,
          height: `${totalHeightRpx}rpx`
        };
      } else {
        return {
          transform: "scale(1)",
          transformOrigin: "top left",
          width: `${totalWidthRpx}rpx`,
          height: `${totalHeightRpx}rpx`
        };
      }
    });
    const gridStyle = common_vendor.computed(() => ({
      display: "grid",
      gridTemplateColumns: `repeat(${props.layout.cols}, ${CARD_WIDTH}rpx)`,
      gridTemplateRows: `repeat(${props.layout.rows}, auto)`,
      // 改为auto，让行高自适应卡片内容
      gap: `${CARD_GAP}rpx`,
      padding: `${CARD_GAP}rpx`
    }));
    const overviewContainerStyle = common_vendor.computed(() => ({
      width: "100%",
      minHeight: "600rpx",
      // 最小高度，允许内容撑开
      overflow: "visible",
      // 允许内容显示
      position: "relative"
    }));
    const scrollContentStyle = common_vendor.computed(() => {
      const totalWidthRpx = props.layout.cols * (CARD_WIDTH + CARD_GAP) + CARD_GAP;
      return {
        width: `${totalWidthRpx}rpx`,
        minWidth: "100%",
        minHeight: "100%"
        // 移除固定高度，让内容自适应
      };
    });
    const getCardPosition = (student) => {
      return {
        gridColumn: student.col,
        gridRow: student.row
      };
    };
    const handleTouchStart = (e) => {
      touchStartTime.value = Date.now();
      touchStartPos.value = {
        x: e.touches[0].clientX,
        y: e.touches[0].clientY
      };
    };
    const handleTouchEnd = () => {
      const touchEndTime = Date.now();
      const touchDuration = touchEndTime - touchStartTime.value;
      if (touchDuration < 300) {
        const now = Date.now();
        if (now - lastTap.value < 300) {
          handleDoubleClick();
        }
        lastTap.value = now;
      }
    };
    const handleDoubleClick = () => {
      common_vendor.index.__f__("log", "at pages/kqjl/components/SeatLayout.vue:213", "双击事件，当前模式:", props.mode);
      if (props.mode === "attendance") {
        const newMode = "overview";
        common_vendor.index.__f__("log", "at pages/kqjl/components/SeatLayout.vue:218", "从点名模式退出到:", newMode);
        emit("modeChange", newMode);
      } else {
        const newMode = "attendance";
        common_vendor.index.__f__("log", "at pages/kqjl/components/SeatLayout.vue:223", "进入点名模式:", newMode);
        emit("modeChange", newMode);
      }
    };
    const handleStatusChange = (statusData) => {
      emit("statusChange", statusData);
    };
    const handleCardClick = (student) => {
      emit("studentClick", student);
    };
    common_vendor.watch(() => props.mode, (newMode, oldMode) => {
      common_vendor.index.__f__("log", "at pages/kqjl/components/SeatLayout.vue:240", "模式变化:", oldMode, "->", newMode);
      if (oldMode === "attendance" && (newMode === "overview" || newMode === "overview-simple")) {
        common_vendor.index.__f__("log", "at pages/kqjl/components/SeatLayout.vue:242", "从点名模式退出，重置页面滚动位置");
        common_vendor.index.pageScrollTo({
          scrollTop: 0,
          duration: 300,
          success: () => {
            common_vendor.index.__f__("log", "at pages/kqjl/components/SeatLayout.vue:249", "页面滚动重置成功");
          },
          fail: (err) => {
            common_vendor.index.__f__("log", "at pages/kqjl/components/SeatLayout.vue:252", "页面滚动重置失败:", err);
          }
        });
        scrollTop.value = 0;
        scrollLeft.value = 0;
        common_vendor.index.__f__("log", "at pages/kqjl/components/SeatLayout.vue:260", "滚动位置重置完成");
      }
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: __props.mode !== "attendance"
      }, __props.mode !== "attendance" ? {
        b: common_vendor.f(__props.students, (student, k0, i0) => {
          return {
            a: student.id,
            b: common_vendor.s(getCardPosition(student)),
            c: common_vendor.o(handleStatusChange, student.id),
            d: common_vendor.o(handleCardClick, student.id),
            e: "2c702716-0-" + i0,
            f: common_vendor.p({
              student,
              ["attendance-mode"]: false
            })
          };
        }),
        c: common_vendor.s(gridStyle.value),
        d: common_vendor.s(layoutStyle.value),
        e: common_vendor.o(handleTouchStart),
        f: common_vendor.o(handleTouchEnd),
        g: common_vendor.s(overviewContainerStyle.value)
      } : {
        h: common_vendor.f(__props.students, (student, k0, i0) => {
          return {
            a: student.id,
            b: common_vendor.s(getCardPosition(student)),
            c: common_vendor.o(handleStatusChange, student.id),
            d: common_vendor.o(handleCardClick, student.id),
            e: "2c702716-1-" + i0,
            f: common_vendor.p({
              student,
              ["attendance-mode"]: true
            })
          };
        }),
        i: common_vendor.s(gridStyle.value),
        j: common_vendor.s(scrollContentStyle.value),
        k: scrollTop.value,
        l: scrollLeft.value,
        m: common_vendor.o(handleTouchStart),
        n: common_vendor.o(handleTouchEnd)
      }, {
        o: common_vendor.gei(_ctx, "")
      });
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2c702716"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/kqjl/components/SeatLayout.js.map
