"use strict";
var common_vendor = require("../../common/vendor.js");
var uni_modules_wotDesignUni_components_wdToast_index = require("../../uni_modules/wot-design-uni/components/wd-toast/index.js");
var uni_modules_wotDesignUni_components_wdMessageBox_index = require("../../uni_modules/wot-design-uni/components/wd-message-box/index.js");
require("../../uni_modules/wot-design-uni/locale/index.js");
require("../../uni_modules/wot-design-uni/dayjs/index.js");
var api_modules_AI = require("../../api/modules/AI.js");
var api_modules_ZhouYi = require("../../api/modules/ZhouYi.js");
var api_modules_question = require("../../api/modules/question.js");
var config_api_config = require("../../config/api.config.js");
require("../../stores/index.js");
var utils_common = require("../../utils/common.js");
var utils_gua_64 = require("../../utils/gua_64.js");
var stores_modules_AIResponse = require("../../stores/modules/AIResponse.js");
var stores_modules_user = require("../../stores/modules/user.js");
require("../../uni_modules/wot-design-uni/components/common/util.js");
require("../../uni_modules/wot-design-uni/components/common/AbortablePromise.js");
require("../../uni_modules/wot-design-uni/locale/lang/zh-CN.js");
require("../../uni_modules/wot-design-uni/dayjs/constant.js");
require("../../uni_modules/wot-design-uni/dayjs/locale/en.js");
require("../../uni_modules/wot-design-uni/dayjs/utils.js");
require("../../api/modules/config.js");
require("../../utils/request.js");
require("../../stores/modules/tabIndex.js");
require("../../stores/modules/rateLimit.js");
if (!Array) {
  const _easycom_wd_button2 = common_vendor.resolveComponent("wd-button");
  const _easycom_wd_text2 = common_vendor.resolveComponent("wd-text");
  const _easycom_wd_input2 = common_vendor.resolveComponent("wd-input");
  const _easycom_wd_img2 = common_vendor.resolveComponent("wd-img");
  const _easycom_wd_message_box2 = common_vendor.resolveComponent("wd-message-box");
  const _easycom_wd_overlay2 = common_vendor.resolveComponent("wd-overlay");
  const _easycom_wd_toast2 = common_vendor.resolveComponent("wd-toast");
  (_easycom_wd_button2 + _easycom_wd_text2 + _easycom_wd_input2 + _easycom_wd_img2 + _easycom_wd_message_box2 + _easycom_wd_overlay2 + _easycom_wd_toast2)();
}
const _easycom_wd_button = () => "../../uni_modules/wot-design-uni/components/wd-button/wd-button.js";
const _easycom_wd_text = () => "../../uni_modules/wot-design-uni/components/wd-text/wd-text.js";
const _easycom_wd_input = () => "../../uni_modules/wot-design-uni/components/wd-input/wd-input.js";
const _easycom_wd_img = () => "../../uni_modules/wot-design-uni/components/wd-img/wd-img.js";
const _easycom_wd_message_box = () => "../../uni_modules/wot-design-uni/components/wd-message-box/wd-message-box.js";
const _easycom_wd_overlay = () => "../../uni_modules/wot-design-uni/components/wd-overlay/wd-overlay.js";
const _easycom_wd_toast = () => "../../uni_modules/wot-design-uni/components/wd-toast/wd-toast.js";
if (!Math) {
  (NavBar + _easycom_wd_button + _easycom_wd_text + _easycom_wd_input + _easycom_wd_img + _easycom_wd_message_box + _easycom_wd_overlay + _easycom_wd_toast)();
}
const NavBar = () => "../../components/NavBar.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "suan-gua",
  setup(__props) {
    const {
      responseText,
      showResponseText,
      isLoading,
      isDone
    } = common_vendor.storeToRefs(stores_modules_AIResponse.useAIReponseStore());
    const {
      yaoList
    } = common_vendor.storeToRefs(stores_modules_user.useUserStore());
    const message = uni_modules_wotDesignUni_components_wdMessageBox_index.useMessage();
    const currentTime = common_vendor.ref(utils_common.formatDate(new Date()));
    const lunarTime = common_vendor.computed$1(() => {
      const d = common_vendor.gt(currentTime.value.substring(0, 16));
      return d.lunar.toString();
    });
    const refreshTime = () => {
      currentTime.value = utils_common.formatDate(new Date());
    };
    const YangImg = config_api_config.BASE_URL + "/uploads/mov_yang_d41e51fd83.png";
    const YinImg = config_api_config.BASE_URL + "/uploads/yin_e32817a811.png";
    const audio = common_vendor.index.createInnerAudioContext();
    audio.autoplay = false;
    audio.src = config_api_config.BASE_URL + "/uploads/01_b7107f6b3b.mp3";
    const ding = common_vendor.index.createInnerAudioContext();
    ding.autoplay = false;
    ding.src = config_api_config.BASE_URL + "/uploads/ding_ae6e65af25.mp3";
    const coinPositiveImg = config_api_config.BASE_URL + "/uploads/_52f5bd86b5.png";
    const coinNegativeImg = config_api_config.BASE_URL + "/uploads/_5f46b99d48.png";
    const toast = uni_modules_wotDesignUni_components_wdToast_index.useToast();
    const coins = common_vendor.ref(["\u6B63\u9762", "\u6B63\u9762", "\u6B63\u9762"]);
    const \u672C\u5366 = common_vendor.ref("");
    const \u53D8\u5366 = common_vendor.ref("");
    const lines = common_vendor.ref([]);
    const randomSide = () => {
      return Math.random() < 0.5 ? "\u6B63\u9762" : "\u53CD\u9762";
    };
    const analyzeYao = (coinResults) => {
      console.log(coinResults);
      const positiveCount = coinResults.filter((v) => v === "\u6B63\u9762").length;
      if (positiveCount === 3) {
        return { type: "\u8001\u9633", isMoving: true, symbol: "\u9633", img: YangImg, number: "9" };
      } else if (positiveCount === 0) {
        return { type: "\u8001\u9634", isMoving: true, symbol: "\u9634", img: YinImg, number: "6" };
      } else if (positiveCount === 2) {
        return { type: "\u5C11\u9634", isMoving: false, symbol: "\u9634", img: YinImg, number: "8" };
      } else {
        return { type: "\u5C11\u9633", isMoving: false, symbol: "\u9633", img: YangImg, number: "7" };
      }
    };
    const resetState = () => {
      lines.value = [];
      coins.value = ["\u6B63\u9762", "\u6B63\u9762", "\u6B63\u9762"];
      \u672C\u5366.value = "";
      \u53D8\u5366.value = "";
      \u4F53\u5366.value = "";
      \u7528\u5366.value = "";
      \u723B\u8F9E.value = "";
      \u52A8\u723B\u5217\u8868.value = [];
      \u9759\u723B\u5217\u8868.value = [];
      inputTxt.value = "";
      showUserAgreeButton.value = true;
      showResponse.value = false;
      audio.pause();
      stores_modules_AIResponse.useAIReponseStore().reset();
    };
    const performCast = () => {
      const newCoins = [randomSide(), randomSide(), randomSide()];
      coins.value = [...newCoins];
      const yao = analyzeYao(newCoins);
      lines.value.unshift(yao);
    };
    common_vendor.ref(false);
    const inputTxt = common_vendor.ref("");
    common_vendor.ref("\u5366\u8C61\u7ED3\u679C\u751F\u6210\u4E2D");
    const \u672C\u5366\u6570\u5B57 = common_vendor.ref("");
    const \u4F53\u5366 = common_vendor.ref("");
    const \u7528\u5366 = common_vendor.ref("");
    const \u52A8\u723B\u5217\u8868 = common_vendor.ref([]);
    common_vendor.ref(0);
    const \u723B\u8F9E = common_vendor.ref("");
    const \u52A8\u723B\u540D\u79F0 = ["\u521D\u4E5D", "\u4E5D\u4E8C", "\u4E5D\u4E09", "\u4E5D\u56DB", "\u4E5D\u4E94", "\u4E0A\u4E5D", "\u521D\u516D", "\u516D\u4E8C", "\u516D\u4E09", "\u516D\u56DB", "\u516D\u4E94", "\u4E0A\u516D"];
    const \u9759\u723B\u5217\u8868 = common_vendor.ref([]);
    const \u83B7\u53D6\u723B\u8F9E\u540D\u79F0 = async () => {
      const len = \u52A8\u723B\u5217\u8868.value.length;
      if (len === 0) {
        return {
          pos: "\u672C\u5366",
          name: "\u65E0"
        };
      }
      if (len === 1) {
        return {
          pos: "\u672C\u5366",
          name: \u52A8\u723B\u5217\u8868.value[0]
        };
      }
      if (len === 2) {
        return {
          pos: "\u672C\u5366",
          name: \u52A8\u723B\u5217\u8868.value[1]
        };
      }
      if (len === 3) {
        return {
          pos: "\u672C\u5366",
          name: \u52A8\u723B\u5217\u8868.value[1]
        };
      }
      if (len === 4) {
        return {
          pos: "\u53D8\u5366",
          name: \u9759\u723B\u5217\u8868.value[0]
        };
      }
      if (len === 5) {
        return {
          pos: "\u53D8\u5366",
          name: \u9759\u723B\u5217\u8868.value[0]
        };
      }
      if (len === 6) {
        if (\u672C\u5366.value === "\u4E7E\u4E3A\u5929") {
          return {
            pos: "\u672C\u5366",
            name: "\u7528\u4E5D"
          };
        } else if (\u672C\u5366.value === "\u5764\u4E3A\u5730") {
          return {
            pos: "\u672C\u5366",
            name: "\u7528\u516D"
          };
        } else {
          return {
            pos: "\u672C\u5366",
            name: "\u65E0"
          };
        }
      }
      return {
        pos: "\u672C\u5366",
        name: "\u65E0"
      };
    };
    const showCompleteLoading = common_vendor.ref(false);
    common_vendor.ref(false);
    common_vendor.watch(
      () => lines.value,
      async (newVal) => {
        if (newVal.length === 6) {
          showCompleteLoading.value = true;
          await utils_common.sleep(3e3);
          showCompleteLoading.value = false;
          setTimeout(() => {
            common_vendor.index.pageScrollTo({
              scrollTop: 999999
            });
          });
          let result1 = "";
          let arr1 = JSON.parse(JSON.stringify(lines.value));
          arr1.reverse().map((line) => {
            result1 += line.symbol;
            \u672C\u5366\u6570\u5B57.value += line.number;
          });
          let result2 = "";
          let arr2 = JSON.parse(JSON.stringify(movingInfo.value));
          arr2.reverse().map((line) => {
            result2 += line.symbol;
          });
          let arr3 = JSON.parse(JSON.stringify(movingInfo.value));
          arr3.reverse().map((line, i) => {
            if (line.isMoving) {
              if (line.number === "6") {
                \u52A8\u723B\u5217\u8868.value.push(\u52A8\u723B\u540D\u79F0[6 + i]);
              }
              if (line.number === "9") {
                \u52A8\u723B\u5217\u8868.value.push(\u52A8\u723B\u540D\u79F0[i]);
              }
            } else {
              if (line.number === "8") {
                \u9759\u723B\u5217\u8868.value.push(\u52A8\u723B\u540D\u79F0[6 + i]);
              }
              if (line.number === "7") {
                \u9759\u723B\u5217\u8868.value.push(\u52A8\u723B\u540D\u79F0[i]);
              }
            }
          });
          for (let i = 0; i < 64; i++) {
            if (utils_gua_64["\u516D\u5341\u56DB\u5366"][i].symbol === result1) {
              \u672C\u5366.value = utils_gua_64["\u516D\u5341\u56DB\u5366"][i].name;
              \u4F53\u5366.value = utils_gua_64["\u516D\u5341\u56DB\u5366"][i].bottom;
              \u7528\u5366.value = utils_gua_64["\u516D\u5341\u56DB\u5366"][i].top;
            }
            if (utils_gua_64["\u516D\u5341\u56DB\u5366"][i].symbol === result2) {
              \u53D8\u5366.value = utils_gua_64["\u516D\u5341\u56DB\u5366"][i].name;
            }
          }
          let _\u723B\u8F9E\u540D\u79F0 = await \u83B7\u53D6\u723B\u8F9E\u540D\u79F0();
          if (_\u723B\u8F9E\u540D\u79F0.name === "\u65E0") {
            \u723B\u8F9E.value = "\u65E0\u52A8\u723B";
          } else {
            if (_\u723B\u8F9E\u540D\u79F0.pos === "\u672C\u5366") {
              \u723B\u8F9E.value = await api_modules_ZhouYi["\u83B7\u53D6\u6613\u7ECF\u723B\u8F9E"](\u672C\u5366.value, _\u723B\u8F9E\u540D\u79F0.name);
            }
            if (_\u723B\u8F9E\u540D\u79F0.pos === "\u53D8\u5366") {
              \u723B\u8F9E.value = await api_modules_ZhouYi["\u83B7\u53D6\u6613\u7ECF\u723B\u8F9E"](\u53D8\u5366.value, _\u723B\u8F9E\u540D\u79F0.name);
            }
          }
          await api_modules_AI.AIChat(
            inputTxt.value,
            \u672C\u5366.value,
            \u53D8\u5366.value,
            \u723B\u8F9E.value
          ).then((res) => {
            if (res.code) {
              toast.error(res.message);
            }
          });
        }
      },
      {
        deep: true
      }
    );
    const showUserAgreeButton = common_vendor.ref(true);
    const agreeMsg = "\u672C\u7A0B\u5E8F\u7CFB\u514D\u8D39\u7684\u6570\u5B57\u5316\u7814\u4E60\u8F85\u52A9\u5DE5\u5177\uFF0C\u6240\u5F62\u6210\u7684\u5185\u5BB9\u53CA\u539F\u6587\u89E3\u8BFB\uFF0C\u4EC5\u4F9B\u5B66\u4E60\u53C2\u8003\u4E4B\u7528\uFF0C\u4E0D\u63D0\u4F9B\u73B0\u5B9E\u4E8B\u52A1\u9884\u6D4B\u3001\u8FD0\u52BF\u5206\u6790\u7B49\u670D\u52A1\u3002";
    const showResponse = common_vendor.ref(false);
    const userAgree = () => {
      message.confirm({
        title: "\u63D0\u793A",
        msg: agreeMsg
      }).then(async () => {
        audio.seek(0);
        audio.play();
        showResponse.value = true;
        showResponseText.value = true;
        isLoading.value = true;
        showUserAgreeButton.value = false;
      });
    };
    const save = () => {
      yaoList.value.unshift({
        time: new Date().getTime(),
        q: inputTxt.value,
        symbol1: \u672C\u5366.value,
        symbol2: \u53D8\u5366.value,
        symbolNum: \u672C\u5366\u6570\u5B57.value,
        result: responseText.value
      });
      responseText.value = "";
      isDone.value = false;
      toast.success("\u4FDD\u5B58\u6210\u529F");
      resetState();
    };
    const coinLoading = common_vendor.ref(false);
    const handleCast = async () => {
      ding.play();
      if (lines.value.length === 6) {
        resetState();
      } else if (lines.value.length === 0) {
        if (inputTxt.value === "") {
          toast.error("\u8BF7\u8F93\u5165\u5F53\u524D\u56F0\u60D1");
          return;
        }
        await api_modules_question.createQ(inputTxt.value);
        const func = await utils_common.rateLimit(
          30 * 60 * 1e3,
          3
        );
        if (!func()) {
          toast.error("\u60A8\u77ED\u65F6\u95F4\u5185\u89E3\u60D1\u6B21\u6570\u8FC7\u591A\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
          return;
        }
        coinLoading.value = true;
        toast.info({
          msg: "\u8BF7\u9759\u5FC3\u7247\u523B\uFF0C\u9ED8\u5FF5\u56F0\u60D1\u4E4B\u4E8B",
          closed: () => {
            performCast();
            coinLoading.value = false;
          }
        });
      } else {
        coinLoading.value = true;
        performCast();
        await utils_common.sleep(1e3);
        coinLoading.value = false;
      }
    };
    const currentStep = common_vendor.computed$1(() => lines.value.length);
    const isComplete = common_vendor.computed$1(() => lines.value.length === 6);
    const buttonText = common_vendor.computed$1(() => {
      if (currentStep.value === 0) {
        return "\u5F00\u59CB\u6F14\u793A";
      } else if (currentStep.value === 6) {
        return "\u91CD\u65B0\u6F14\u793A";
      } else {
        return `\u7EE7\u7EED\u6F14\u793A`;
      }
    });
    const displayLines = common_vendor.computed$1(() => {
      const positionNames = ["\u521D\u723B", "\u4E8C\u723B", "\u4E09\u723B", "\u56DB\u723B", "\u4E94\u723B", "\u4E0A\u723B"];
      return lines.value.map((line, index) => ({
        position: positionNames[index],
        symbol: line.symbol,
        img: line.img,
        number: line.number
      }));
    });
    const movingInfo = common_vendor.computed$1(() => {
      const movingIndices = [];
      lines.value.forEach((line, idx) => {
        let item = {
          ...line,
          img: line.img
        };
        if (line.isMoving) {
          item.position = `\u7B2C${6 - idx}\u723B\u52A8`;
          item.symbol = line.symbol === "\u9634" ? "\u9633" : "\u9634";
          if (line.type === "\u8001\u9634")
            item.img = YangImg;
          if (line.type === "\u8001\u9633")
            item.img = YinImg;
        }
        movingIndices.push(item);
      });
      return movingIndices;
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.p({
          title: "\u7814\u4E60"
        }),
        b: common_vendor.o(refreshTime),
        c: common_vendor.p({
          size: "small",
          type: "icon",
          icon: "refresh"
        }),
        d: common_vendor.p({
          text: "\u5F53\u524D\u65F6\u95F4",
          bold: true,
          color: "#333"
        }),
        e: common_vendor.p({
          text: "\u516C\u5386",
          color: "#999"
        }),
        f: common_vendor.p({
          text: currentTime.value,
          bold: true,
          color: "#333"
        }),
        g: common_vendor.p({
          text: "\u519C\u5386",
          color: "#999"
        }),
        h: common_vendor.p({
          text: common_vendor.unref(lunarTime),
          bold: true,
          color: "#333"
        }),
        i: common_vendor.p({
          text: "\u5F53\u524D\u56F0\u60D1",
          bold: true,
          color: "#333"
        }),
        j: common_vendor.o(($event) => inputTxt.value = $event),
        k: common_vendor.p({
          placeholder: "\u8BF7\u8F93\u5165",
          disabled: lines.value.length !== 0,
          modelValue: inputTxt.value
        }),
        l: common_vendor.t(common_vendor.unref(buttonText)),
        m: common_vendor.o(handleCast),
        n: common_vendor.p({
          type: "warning",
          size: "large",
          ["custom-style"]: {
            backgroundColor: "#145060",
            fontSize: "32rpx"
          },
          loading: coinLoading.value,
          block: true,
          disabled: common_vendor.unref(showResponseText) && !common_vendor.unref(isDone)
        }),
        o: lines.value.length
      }, lines.value.length ? {
        p: common_vendor.f(coins.value, (coin, index, i0) => {
          return {
            a: "14c39f7b-10-" + i0,
            b: common_vendor.p({
              src: coin === "\u6B63\u9762" ? coinPositiveImg : coinNegativeImg,
              width: "100%",
              height: "100%",
              mode: "aspectFill"
            }),
            c: index
          };
        })
      } : {}, {
        q: common_vendor.p({
          text: "\u5F53\u524D",
          size: "28rpx",
          bold: true,
          color: "#333"
        }),
        r: \u672C\u5366.value
      }, \u672C\u5366.value ? {
        s: common_vendor.t(\u672C\u5366.value),
        t: common_vendor.o(($event) => common_vendor.unref(utils_common.goTo)(`/pages/ZhouYi/detail?name=${\u672C\u5366.value}`)),
        v: common_vendor.p({
          size: "small",
          plain: true,
          ["custom-style"]: {
            border: "#4b3a2b 2px solid",
            color: "#4b3a2b",
            fontSize: "24rpx"
          }
        })
      } : {}, {
        w: lines.value.length === 0
      }, lines.value.length === 0 ? {} : {
        x: common_vendor.f(common_vendor.unref(displayLines), (line, idx, i0) => {
          return {
            a: idx,
            b: `url(${line.img})`
          };
        })
      }, {
        y: common_vendor.p({
          text: "\u53D8\u5316",
          size: "28rpx",
          bold: true,
          color: "#333"
        }),
        z: \u53D8\u5366.value
      }, \u53D8\u5366.value ? {
        A: common_vendor.t(\u53D8\u5366.value),
        B: common_vendor.o(($event) => common_vendor.unref(utils_common.goTo)(`/pages/ZhouYi/detail?name=${\u53D8\u5366.value}`)),
        C: common_vendor.p({
          size: "small",
          plain: true,
          ["custom-style"]: {
            border: "#4b3a2b 2px solid",
            color: "#4b3a2b",
            fontSize: "24rpx"
          }
        })
      } : {}, {
        D: common_vendor.unref(movingInfo).length === 0
      }, common_vendor.unref(movingInfo).length === 0 ? {
        E: common_vendor.t(lines.value.length === 0 ? "\u6682\u65E0" : "\u65E0\u52A8\u723B")
      } : {
        F: common_vendor.f(common_vendor.unref(movingInfo), (info, idx, i0) => {
          return {
            a: idx,
            b: `url(${info.img})`
          };
        })
      }, {
        G: common_vendor.p({
          text: "\u5185\u5BB9\u89E3\u6790",
          bold: true,
          color: "#333"
        }),
        H: !common_vendor.unref(isComplete)
      }, !common_vendor.unref(isComplete) ? {
        I: common_vendor.p({
          text: "\u6682\u65E0",
          color: "#333"
        })
      } : {}, {
        J: common_vendor.unref(isComplete) && showUserAgreeButton.value && !showCompleteLoading.value
      }, common_vendor.unref(isComplete) && showUserAgreeButton.value && !showCompleteLoading.value ? {
        K: common_vendor.o(userAgree),
        L: common_vendor.p({
          block: true,
          size: "large",
          ["custom-style"]: {
            backgroundColor: "#145060",
            fontSize: "32rpx"
          }
        })
      } : {}, {
        M: showResponse.value
      }, showResponse.value ? common_vendor.e({
        N: common_vendor.p({
          text: "\u539F\u6587",
          bold: true,
          color: "#333"
        }),
        O: \u723B\u8F9E.value
      }, \u723B\u8F9E.value ? {
        P: common_vendor.p({
          text: \u723B\u8F9E.value,
          color: "#666"
        })
      } : {
        Q: common_vendor.p({
          text: "\u6682\u65E0",
          color: "#666"
        })
      }, {
        R: common_vendor.p({
          text: "\u89E3\u6790",
          bold: true,
          color: "#333"
        }),
        S: !common_vendor.unref(isComplete)
      }, !common_vendor.unref(isComplete) ? {
        T: common_vendor.p({
          text: "\u6682\u65E0",
          color: "#666"
        })
      } : {}, {
        U: common_vendor.unref(showResponseText) && common_vendor.unref(responseText)
      }, common_vendor.unref(showResponseText) && common_vendor.unref(responseText) ? {
        V: common_vendor.p({
          text: common_vendor.unref(responseText),
          color: "#666"
        })
      } : {}, {
        W: common_vendor.unref(isDone) && common_vendor.unref(showResponseText)
      }, common_vendor.unref(isDone) && common_vendor.unref(showResponseText) ? {
        X: common_vendor.o(save),
        Y: common_vendor.p({
          block: true,
          size: "large",
          ["custom-style"]: {
            backgroundColor: "#145060",
            fontSize: "32rpx"
          }
        })
      } : {}) : {}, {
        Z: common_vendor.p({
          text: "\u63D0\u793A",
          size: "32rpx",
          color: "#333"
        }),
        aa: common_vendor.p({
          text: "\u4FE1\u606F\u5DF2\u751F\u6210\uFF0C\u6B63\u5728\u6574\u7406\u539F\u6587\u4E0E\u76F8\u5173\u8D44\u6599.....",
          size: "28rpx",
          color: "#333"
        }),
        ab: common_vendor.p({
          show: showCompleteLoading.value,
          ["lock-scroll"]: true
        }),
        ac: common_vendor.p({
          position: "middle"
        })
      });
    };
  }
});
var Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-14c39f7b"], ["__file", "D:/\u7F51\u6291\u4E91Time/\u79C1\u6D3B/2000\u7B97\u5366/src/pages/suan-gua/suan-gua.vue"]]);
wx.createComponent(Component);
