"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_assets = require("../../../common/assets.js");
const utils_emitter = require("../../../utils/emitter.js");
if (!Array) {
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  _easycom_uni_popup2();
}
const _easycom_uni_popup = () => "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  (tipVue + _easycom_uni_popup)();
}
const tipVue = () => "./tip.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "timeSelect",
  setup(__props) {
    let selectObj = common_vendor.ref([]);
    let fontColor = common_vendor.ref([]);
    let itemSelectObj = common_vendor.ref([]);
    let itemFontColor = common_vendor.ref([]);
    common_vendor.wx$1.getStorageSync("cookie");
    const appIdx = common_vendor.ref(0);
    const cnt = common_vendor.ref(1);
    const productObject = common_vendor.ref({});
    const appointmentDateVOList = common_vendor.ref([]);
    let appointmentDate = "";
    let timeSlot = "";
    const restNumber = common_vendor.ref("请选择时间段");
    let countMap = /* @__PURE__ */ new Map();
    common_vendor.onMounted(() => {
      closeyyxzTip();
      utils_emitter.emitter.on("getGoodData", (val) => {
        productObject.value = val;
        appointmentDateVOList.value = val.appointmentDateVOList;
        selectObj.value = new Array(appointmentDateVOList.value.length).fill(null).map(() => ({
          backgroundColor: "#fff",
          borderColor: "#C35C5D"
        }));
        fontColor.value = new Array(appointmentDateVOList.value.length).fill(null).map(() => ({
          color: "#323233"
        }));
        selectObj.value[0] = { backgroundColor: "#FBDEDF", borderColor: "#FBDEDF" };
        fontColor.value[0] = { color: "#C35C5D" };
        for (var i = 0; i < appointmentDateVOList.value.length; i++) {
          var col = appointmentDateVOList.value[i].timePeriodVOList.length;
          itemSelectObj.value[i] = new Array(col).fill(null).map(() => ({
            backgroundColor: "#F3F3F3"
          }));
          itemFontColor.value[i] = new Array(col).fill(null).map(() => ({
            color: "#323233"
          }));
        }
      });
      utils_emitter.emitter.on("getBookingNumberMap", (val) => {
        countMap = val;
        console.log("==============>", val);
        appointmentDate = appointmentDateVOList.value[appIdx.value].specificDate;
      });
    });
    const maskClosehandler = () => {
    };
    const tip = common_vendor.ref(null);
    const closeyyxzTip = () => {
      utils_emitter.emitter.on("closeyyxzTip", () => {
        tip.value.close();
      });
    };
    const openyyxzTip = () => {
      tip.value.open();
    };
    const add = () => {
      if (restNumber.value === "请选择时间段") {
        common_vendor.index.showToast({
          title: "请选择时间段",
          icon: "error"
        });
        return;
      }
      if (cnt.value < Number(restNumber.value)) {
        cnt.value++;
      }
    };
    const sub = () => {
      if (cnt.value > 1) {
        cnt.value--;
      }
    };
    const close = () => {
      utils_emitter.emitter.emit("closeTimeDialog");
    };
    const isSelected = (index) => {
      appIdx.value = index;
      restNumber.value = "请选择时间段";
      appointmentDate = appointmentDateVOList.value[appIdx.value].specificDate;
      console.log("appointmentDate===================================>", appointmentDate);
      for (var i = 0; i < appointmentDateVOList.value.length; i++) {
        if (i == index) {
          selectObj.value[i].backgroundColor = "#FBDEDF";
          selectObj.value[i].borderColor = "#FBDEDF";
          fontColor.value[i].color = "#C35C5D";
        } else {
          selectObj.value[i].backgroundColor = "#fff";
          selectObj.value[i].borderColor = "#C35C5D";
          fontColor.value[i].color = "#323233";
        }
      }
      var col = appointmentDateVOList.value[appIdx.value].timePeriodVOList.length;
      for (var i = 0; i < col; i++) {
        itemSelectObj.value[appIdx.value][i].backgroundColor = "#F3F3F3";
        itemFontColor.value[appIdx.value][i].color = "#323233";
      }
    };
    const itemIsSelected = (index) => {
      timeSlot = appointmentDateVOList.value[appIdx.value].timePeriodVOList[index].timeSlot;
      restNumber.value = countMap[appointmentDate + "&" + timeSlot];
      console.log("timeSlot====================================>", timeSlot);
      var col = appointmentDateVOList.value[appIdx.value].timePeriodVOList.length;
      for (var i = 0; i < col; i++) {
        if (i == index) {
          itemSelectObj.value[appIdx.value][i].backgroundColor = "#FBDEDF";
          itemFontColor.value[appIdx.value][i].color = "#C35C5D";
        } else {
          itemSelectObj.value[appIdx.value][i].backgroundColor = "#F3F3F3";
          itemFontColor.value[appIdx.value][i].color = "#323233";
        }
      }
    };
    return (_ctx, _cache) => {
      return {
        a: productObject.value.goodImg,
        b: common_vendor.o(($event) => close()),
        c: common_assets._imports_0,
        d: common_vendor.t(appointmentDateVOList.value[appIdx.value].specificDate),
        e: common_vendor.t(restNumber.value),
        f: common_assets._imports_1,
        g: common_vendor.o(($event) => openyyxzTip()),
        h: common_vendor.f(appointmentDateVOList.value, (item, index, i0) => {
          return {
            a: common_vendor.s(common_vendor.unref(fontColor)[index]),
            b: common_vendor.t(item.specificDate.substring(5)),
            c: common_vendor.s(common_vendor.unref(fontColor)[index]),
            d: common_vendor.s(common_vendor.unref(selectObj)[index]),
            e: index,
            f: common_vendor.o(($event) => isSelected(index), index)
          };
        }),
        i: common_vendor.f(appointmentDateVOList.value[appIdx.value].timePeriodVOList, (item, index, i0) => {
          return {
            a: common_vendor.t(item.timeSlot),
            b: common_vendor.s(common_vendor.unref(itemFontColor)[appIdx.value][index]),
            c: index,
            d: common_vendor.o(($event) => itemIsSelected(index), index),
            e: common_vendor.s(common_vendor.unref(itemSelectObj)[appIdx.value][index])
          };
        }),
        j: common_vendor.o(sub),
        k: common_assets._imports_2,
        l: common_vendor.t(cnt.value),
        m: common_vendor.o(add),
        n: common_assets._imports_3,
        o: common_vendor.sr(tip, "73c3a893-0", {
          "k": "tip"
        }),
        p: common_vendor.o(maskClosehandler),
        q: common_vendor.p({
          animation: false
        })
      };
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-73c3a893"], ["__file", "D:/微信小程序/课设整合/匠承非遗小程序端/jiangchengfeiyi-xiaochengxu/pages/workshop/component/timeSelect.vue"]]);
wx.createComponent(Component);
