import { _ as _export_sfc, a as defineComponent, r as resolveComponent, c as createBlock, o as openBlock, w as withCtx, b as createVNode, g as createBaseVNode, S as normalizeClass, O as toDisplayString, Q as QIcon, e as QBtn } from "./index-BRudWVF6.js";
import { Q as QInput } from "./QInput-C1k2VUPF.js";
import { Q as QPage } from "./QPage-y4zftl3-.js";
import { A as AppHeader } from "./AppHeader-DugPHj8B.js";
import { u as utils } from "./utils-DT9w33jF.js";
import "./use-id-Bga_UBPy.js";
const url = "http://9l7.cn/10lrE";
const _sfc_main = defineComponent({
  name: "ActivationPage",
  components: {
    AppHeader
  },
  data() {
    return {
      isVip: false,
      expireDate: null,
      code: "",
      loading: false,
      url
    };
  },
  mounted() {
    this.getLink();
    this.getUserInfo();
  },
  methods: {
    async getLink() {
      try {
        let res = await this.$api.get("/api/main/vip/activation");
        if (res?.url) {
          this.url = res.url;
        }
      } catch (err) {
        this.url = url;
      }
    },
    async getUserInfo() {
      try {
        let res = await this.$api.get("/api/main/user/info");
        if (res) {
          this.isVip = res.status === 1;
          this.expireDate = res.expireDate;
        }
      } catch (err) {
        this.url = url;
      }
    },
    async onSubmit() {
      if (!this.code) {
        utils.notifyError("请输入激活码");
        return;
      }
      this.loading = true;
      try {
        let res = await this.$api.post("/api/main/vip/activation", { code: this.code });
        if (res && res.userId && res.expireDate) {
          utils.notifySuccess("激活成功");
          this.isVip = true;
          this.expireDate = res.expireDate;
          console.log("-------  ", res);
        }
      } catch (err) {
        utils.notifyError(err.message || "激活失败");
      } finally {
        this.loading = false;
      }
    },
    onBuy() {
      window.open(this.url, "_blank");
    }
  }
});
const _hoisted_1 = { class: "col column justify-center items-center activation-content" };
const _hoisted_2 = { class: "flex flex-center column" };
const _hoisted_3 = { class: "full-width q-px-lg" };
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  const _component_app_header = resolveComponent("app-header");
  return openBlock(), createBlock(QPage, { class: "popup-page bg-white column" }, {
    default: withCtx(() => [
      createVNode(_component_app_header),
      createBaseVNode("div", _hoisted_1, [
        createBaseVNode("div", _hoisted_2, [
          createBaseVNode("div", {
            class: normalizeClass(_ctx.isVip ? "text-bold" : "")
          }, "当前会员类型：" + toDisplayString(_ctx.isVip ? "VIP会员" : "普通会员"), 3),
          createBaseVNode("div", null, toDisplayString(_ctx.expireDate ? "过期时间：" + _ctx.expireDate : ""), 1)
        ]),
        _cache[2] || (_cache[2] = createBaseVNode("div", { style: { "height": "50px" } }, null, -1)),
        createBaseVNode("div", _hoisted_3, [
          _cache[1] || (_cache[1] = createBaseVNode("div", { class: "text-subtitle1 text-weight-bold text-grey-9" }, "输入激活码:", -1)),
          createVNode(QInput, {
            modelValue: _ctx.code,
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.code = $event),
            placeholder: "激活码",
            outlined: "",
            dense: "",
            class: "activation-input"
          }, {
            prepend: withCtx(() => [
              createVNode(QIcon, {
                name: "vpn_key",
                color: "grey-5",
                size: "xs"
              })
            ]),
            _: 1
          }, 8, ["modelValue"]),
          createVNode(QBtn, {
            label: "确定",
            color: "primary",
            class: "full-width q-mt-md",
            rounded: "",
            unelevated: "",
            loading: _ctx.loading,
            onClick: _ctx.onSubmit
          }, null, 8, ["loading", "onClick"]),
          createVNode(QBtn, {
            icon: "shopping_cart",
            label: "购买激活码",
            color: "positive",
            class: "full-width q-mt-md",
            outline: "",
            rounded: "",
            unelevated: "",
            onClick: _ctx.onBuy
          }, null, 8, ["onClick"])
        ])
      ])
    ]),
    _: 1
  });
}
const Activation = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-3ed679e3"]]);
export {
  Activation as default
};
