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, Q as QIcon, h as createElementBlock, P as Fragment, R as renderList, S as normalizeClass, M as createCommentVNode, i as createTextVNode, O as toDisplayString, e as QBtn } from "./index-BRudWVF6.js";
import { Q as QCard } from "./QCard-S3y3u9tH.js";
import { Q as QBadge, A as AppHeader } from "./AppHeader-DugPHj8B.js";
import { Q as QPage } from "./QPage-y4zftl3-.js";
import { u as utils } from "./utils-DT9w33jF.js";
import "./use-id-Bga_UBPy.js";
const _sfc_main = defineComponent({
  name: "VipPage",
  components: {
    AppHeader
  },
  data() {
    return {
      selectedPlanId: null,
      loading: false,
      plans: [],
      benefits: [
        "批量操作不限次数",
        "优先体验新功能",
        "专属客服支持"
      ]
    };
  },
  computed: {
    currentPlan() {
      return this.plans.find((p) => p.id === this.selectedPlanId) || {};
    }
  },
  mounted() {
    const token = localStorage.getItem("token");
    if (!token) this.$router.replace("/");
    this.fetchPlans();
  },
  methods: {
    async fetchPlans() {
      try {
        const res = await this.$api.post("/api/main/vip/list");
        if (res) {
          this.plans = res.map((p) => ({
            id: p.id,
            name: p.name,
            price: p.price,
            badge: p.description || "",
            // 使用 description 作为 badge
            link: p.link || ""
          }));
          if (this.plans.length > 0) {
            this.selectedPlanId = this.plans[0].id;
          }
        }
      } catch (err) {
        utils.notifyError("获取套餐失败");
      }
    },
    playIntro() {
      utils.notifyError("演示视频待接入");
    },
    openVip() {
      if (!this.selectedPlanId) {
        utils.notifyError("请选择套餐");
        return;
      }
      const findPlan = this.plans.find((p) => p.id === this.selectedPlanId);
      if (findPlan.link) {
        window.open(findPlan.link, "_blank");
      } else {
        utils.notifyError("套餐链接不存在");
      }
    }
  }
});
const _hoisted_1 = { class: "vip-body q-pa-lg" };
const _hoisted_2 = { class: "vip-video-overlay" };
const _hoisted_3 = { class: "vip-plans q-mt-md" };
const _hoisted_4 = { class: "vip-plan-left" };
const _hoisted_5 = { class: "vip-plan-name" };
const _hoisted_6 = {
  key: 0,
  class: "vip-plan-desc text-caption text-grey-7"
};
const _hoisted_7 = { class: "vip-plan-price" };
const _hoisted_8 = { class: "vip-plan-price-num" };
const _hoisted_9 = { class: "vip-bottom" };
const _hoisted_10 = { class: "vip-bottom-inner q-px-lg q-pt-md q-pb-md" };
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  const _component_app_header = resolveComponent("app-header");
  return openBlock(), createBlock(QPage, { class: "popup-page vip-page" }, {
    default: withCtx(() => [
      createVNode(_component_app_header),
      createBaseVNode("div", _hoisted_1, [
        createVNode(QCard, {
          class: "vip-video-card",
          bordered: ""
        }, {
          default: withCtx(() => [
            createBaseVNode("div", {
              class: "vip-video",
              onClick: _cache[0] || (_cache[0] = (...args) => _ctx.playIntro && _ctx.playIntro(...args))
            }, [
              createBaseVNode("div", _hoisted_2, [
                createVNode(QIcon, {
                  name: "play_circle_filled",
                  size: "64px",
                  color: "white"
                }),
                _cache[1] || (_cache[1] = createBaseVNode("div", { class: "vip-video-text" }, "功能演示", -1))
              ])
            ])
          ]),
          _: 1
        }),
        _cache[2] || (_cache[2] = createBaseVNode("div", { class: "vip-section-title q-mt-lg" }, "选择套餐", -1)),
        createBaseVNode("div", _hoisted_3, [
          (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.plans, (plan) => {
            return openBlock(), createBlock(QCard, {
              key: plan.id,
              class: normalizeClass(["vip-plan", { "is-selected": _ctx.selectedPlanId === plan.id }]),
              bordered: "",
              onClick: ($event) => _ctx.selectedPlanId = plan.id
            }, {
              default: withCtx(() => [
                createBaseVNode("div", _hoisted_4, [
                  createBaseVNode("div", _hoisted_5, [
                    createTextVNode(toDisplayString(plan.name) + " ", 1),
                    plan.badge ? (openBlock(), createBlock(QBadge, {
                      key: 0,
                      class: "q-ml-sm",
                      color: "negative",
                      rounded: "",
                      label: plan.badge
                    }, null, 8, ["label"])) : createCommentVNode("", true)
                  ]),
                  plan.desc ? (openBlock(), createElementBlock("div", _hoisted_6, toDisplayString(plan.desc), 1)) : createCommentVNode("", true)
                ]),
                createBaseVNode("div", _hoisted_7, [
                  createBaseVNode("div", _hoisted_8, "¥" + toDisplayString(plan.price), 1)
                ])
              ]),
              _: 2
            }, 1032, ["class", "onClick"]);
          }), 128))
        ])
      ]),
      createBaseVNode("div", _hoisted_9, [
        createBaseVNode("div", _hoisted_10, [
          createVNode(QBtn, {
            class: "vip-cta",
            color: "primary",
            label: "立即开通",
            unelevated: "",
            rounded: "",
            "no-caps": "",
            size: "lg",
            loading: _ctx.loading,
            onClick: _ctx.openVip
          }, null, 8, ["loading", "onClick"])
        ])
      ])
    ]),
    _: 1
  });
}
const Vip = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-4c335dac"]]);
export {
  Vip as default
};
