<script setup>
import PageHero from "../components/PageHero.vue";
import { Icon } from "@iconify/vue";
import { onBeforeUnmount, onMounted, ref } from "vue";

const activeTab = ref("platform");
const tabBarRef = ref(null);
const prefersReducedMotion = () =>
  typeof window !== "undefined" &&
  window.matchMedia &&
  window.matchMedia("(prefers-reduced-motion: reduce)").matches;

const pillars = [
  {
    key: "platform",
    title: "工业互联网平台",
    lead: "油气专属底座，打通“数采—数据—系统—AI”，为全场景应用落地提供稳定支撑。",
    icon: "lucide:layers-3",
    items: [
      {
        title: "油气专属底座 · 适配全场景需求",
        desc: "聚焦油气领域专属场景，深度适配数采、大模型相关各类应用需求，可灵活承载勘探、开发等全环节数字化场景，贴合行业业务特性。",
      },
      {
        title: "高兼容架构 · 打破系统壁垒",
        desc: "采用高兼容技术架构，可无缝对接油气领域各类数采设备、现有系统及大模型应用，实现数据互通、系统联动，降低对接成本。",
      },
      {
        title: "灵活可扩展 · 承载多元需求",
        desc: "平台底座具备高度灵活性与可扩展性，可根据油气领域不同场景、不同需求，灵活承载数采、大模型相关各类数字化应用落地。",
      },
    ],
  },
  {
    key: "equipment",
    title: "设备管理",
    lead: "围绕设备全生命周期，实现台账、巡检维保、预测维护与实时监控预警的闭环管理。",
    icon: "lucide:cpu",
    items: [
      {
        title: "全维度设备管理 · 筑牢管控基础",
        desc: "依托平台底座，承载油气领域设备全生命周期管理场景，兼容各类数采设备，实现设备台账、参数信息统一管控，适配不同型号、不同环节油气设备，高效统筹设备资源。",
      },
      {
        title: "智慧维保巡检 · 降低运维成本",
        desc: "联动巡检、维保全流程，支持自定义巡检计划与维保流程，无缝对接现场数采数据，实现维保巡检标准化、规范化，减少人工冗余，提高运维效率。",
      },
      {
        title: "预测性维护 · 防范设备风险",
        desc: "借助平台大模型与数采技术支撑，实时分析设备运行数据，精准预测潜在故障并提前触发维护提醒，规避停机风险，降低故障损失。",
      },
      {
        title: "实时监控预警 · 保障作业安全",
        desc: "实时采集运行参数，实现设备状态可视化监控；异常情况快速预警、精准推送，适配油气现场复杂作业环境，筑牢安全生产防线。",
      },
    ],
  },
  {
    key: "production",
    title: "生产管理",
    lead: "面向油气生产项目，贯通任务、计划、数据与报表，提升协同效率与过程可控性。",
    icon: "lucide:clipboard-check",
    items: [
      {
        title: "项目任务管理 · 联动平台高效统筹",
        desc: "承接油气领域生产项目全流程任务管理，无缝对接平台数据体系，实现任务分配、进度跟踪、闭环管理，统筹项目各环节，确保生产任务有序推进。",
      },
      {
        title: "计划与实际联动 · 精准把控生产节奏",
        desc: "基于平台数采能力，科学制定生产计划；同步对接生产实际数据，自动匹配计划与实际差异，实时调整生产安排，保障流程高效衔接。",
      },
      {
        title: "自动报表生成 · 沉淀核心数据资产",
        desc: "自动汇总数采数据、生产进度与任务完成情况，一键生成日报、月报等报表，减少人工录入，实现生产数据规范化保存与资产沉淀。",
      },
      {
        title: "全流程数智赋能 · 提升生产整体效能",
        desc: "深度联动平台数采与数据管理能力，打造生产计划、任务执行、数据统计全链条，减少人工冗余，提升协同效率，实现数字化、智能化转型。",
      },
    ],
  },
  {
    key: "qhse",
    title: "QHSE",
    lead: "以合规为底线，以数据为驱动，实现风险隐患闭环与作业全过程可控，助力管理升级。",
    icon: "lucide:shield-check",
    items: [
      {
        title: "合规适配QHSE体系 · 筑牢安全底线",
        desc: "全面贴合QHSE管理体系标准，覆盖风险隐患、作业许可、环境管理等核心模块，确保管理流程合规达标，契合油气行业安全环保监管要求，规避合规风险。",
      },
      {
        title: "多系统集成联动 · 实现协同管控",
        desc: "深度集成设备管理、生产管理等系统，实现数据互通、流程联动，同步设备状态、作业计划等数据，打破系统壁垒，构建安全+生产+设备一体化管控体系。",
      },
      {
        title: "全维度风险防控 · 保障作业安全",
        desc: "整合风险隐患管理、应急与健康管理、作业许可与过程监督等功能，借助数采与数据处理能力，实现风险精准识别、隐患闭环治理、作业全过程可控。",
      },
      {
        title: "体系化支撑 · 赋能管理升级",
        desc: "涵盖目标管理、培训与体系支持等模块，联动平台数据资产，实现目标拆解、培训落地与体系落地，推动从被动应对到主动防控转型，提升管理效能。",
      },
    ],
  },
];

const deliver = [
  { title: "SaaS", desc: "开箱即用，按需订阅，快速试点与复制。" },
  { title: "私有化", desc: "数据本地化部署，适配企业安全与合规要求。" },
  { title: "混合云", desc: "核心数据本地，弹性算力上云，兼顾成本与性能。" },
];

function headerOffsetPx() {
  const rootStyle = getComputedStyle(document.documentElement);
  const headerVar = rootStyle.getPropertyValue("--header-h")?.trim();
  const headerH = Number.parseFloat(headerVar || "72") || 72;
  const tabH = tabBarRef.value?.getBoundingClientRect?.().height || 0;
  return Math.round(headerH + tabH + 16);
}

function scrollToTab(key) {
  const el = document.getElementById(`product-${key}`);
  if (!el) return;
  activeTab.value = key;

  const offset = headerOffsetPx();
  const y = el.getBoundingClientRect().top + window.scrollY - offset;
  window.scrollTo({
    top: Math.max(0, y),
    behavior: prefersReducedMotion() ? "auto" : "smooth",
  });
}

let observer = null;
onMounted(() => {
  const offset = headerOffsetPx();
  observer = new IntersectionObserver(
    (entries) => {
      const visible = entries
        .filter((e) => e.isIntersecting)
        .sort(
          (a, b) => (b.intersectionRatio || 0) - (a.intersectionRatio || 0),
        )[0];
      if (visible?.target?.id)
        activeTab.value = visible.target.id.replace("product-", "");
    },
    {
      root: null,
      threshold: [0.25, 0.45, 0.6],
      rootMargin: `-${offset}px 0px -55% 0px`,
    },
  );

  for (const p of pillars) {
    const el = document.getElementById(`product-${p.key}`);
    if (el) observer.observe(el);
  }
});

onBeforeUnmount(() => {
  observer?.disconnect?.();
  observer = null;
});
</script>

<template>
  <div class="productsView">
    <PageHero
      kicker=""
      title="油气行业数智产品矩阵"
      subtitle="以工业互联网平台为底座，覆盖设备管理、生产管理与QHSE，贯通数采、数据、流程与AI，支撑从勘探开发到生产运营的全场景数字化。"
    >
      <template #actions>
        <RouterLink
          class="btn btn-primary"
          style="border-radius: 0"
          to="/contact"
          >获取产品资料</RouterLink
        >
      </template>
    </PageHero>

    <section class="section" style="padding-top: 0; margin-top: -10px">
      <div>
        <div
          ref="tabBarRef"
          class="tabBar"
          role="tablist"
          aria-label="产品域导航"
        >
          <button
            v-for="p in pillars"
            :key="p.key"
            class="tabBtn"
            :class="{ 'is-active': activeTab === p.key }"
            type="button"
            role="tab"
            :aria-selected="activeTab === p.key ? 'true' : 'false'"
            @click="scrollToTab(p.key)"
          >
            <span
              class="tabText"
              style="display: flex; align-items: center; gap: 10px"
              ><Icon :icon="p.icon" width="18" height="18" aria-hidden="true" />
              <span>{{ p.title }}</span></span
            >
          </button>
        </div>

        <div class="productStac container">
          <section
            v-for="p in pillars"
            :id="`product-${p.key}`"
            :key="p.key"
            class="productSection"
          >
            <header class="productHead">
              <div class="productHeadTop">
                <h2 class="productTitle">{{ p.title }}</h2>
              </div>
              <p class="productLead">{{ p.lead }}</p>
            </header>

            <div class="productBody">
              <div v-for="it in p.items" :key="it.title" class="featureRow">
                <div class="featureDot" aria-hidden="true"></div>
                <div class="featureMain">
                  <div class="featureTitle">{{ it.title }}</div>
                  <div class="muted featureDesc">{{ it.desc }}</div>
                </div>
              </div>
            </div>
          </section>
        </div>
      </div>
    </section>

    <section class="section section--soft">
      <div class="container">
        <div class="sectionHead">
          <div>
            <!-- <div class="section-kicker">交付方式</div> -->
            <h2 class="h2">灵活适配企业IT与合规边界</h2>
            <div class="muted">
              支持试点快速落地，也支持规模化推广与安全合规的长期运行。
            </div>
          </div>
        </div>

        <div class="grid grid-3">
          <div
            v-for="d in deliver"
            :key="d.title"
            class="card card-pad deliverCard"
            style="border: none; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.05)"
          >
            <div class="deliverTitle">{{ d.title }}</div>
            <div class="muted">{{ d.desc }}</div>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<style scoped>
/* 在 <style scoped> 内部添加以下内容 */

.productsView {
  --ink: rgba(2, 6, 23, 0.92);
  --tab-bg: rgba(255, 255, 255, 0.92);
}

.sectionHead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.productStac {
  display: flex;
  width: 100%;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

/* Remove PageHero gradients for this page */
:deep(.pageHero) {
  background-image: url("../assets/images/bg3.png");

  background-size: cover, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
  background-blend-mode: overlay;
  color: #111;
  border-bottom: none;
  padding: 80px 0;
}
:deep(.pageHero__subtitle) {
  color: #4f5055;
}

.tabBar {
  position: sticky;
  top: var(--header-h);
  padding: 0 30px;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0px;
  background: #eef5f8;
  margin: 10px 0 18px;
  height: 80px;
  border: 0;
  border-radius: 0;
}

.tabBtn {
  height: 80px;
  font-size: 20px;
  border: 0;
  background: #eef5f8;
  box-shadow: var(--tab-shadow);
  padding: 0 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--slate-700);

  letter-spacing: 0.01em;
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    color 160ms ease;
}

.tabBtn.is-active {
  color: var(--brand-700);
  background-color: #fff;
}

.tabBtn:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(37, 99, 235, 0.24),
    var(--tab-shadow-hover);
}

.tabText {
  display: inline-block;
  white-space: nowrap;
  padding-bottom: 10px;
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0 2px;
  transition: background-size 160ms ease;
}

.tabBtn.is-active .tabText {
  background-size: 100% 2px;
}

.productStack {
  display: grid;
  gap: 26px;
}

.productSection {
  scroll-margin-top: calc(var(--header-h) + 84px);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  margin-top: 50px;
}

.productHead {
  padding: 18px 18px 14px;

  text-align: center;
}

.productHeadTop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.productBadge {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: rgba(2, 6, 23, 0.65);
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid rgba(15, 23, 42, 0.08);
  padding: 6px 10px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.productTitle {
  letter-spacing: -0.02em;
  color: var(--ink);
  font-size: 30px;
  line-height: 1.25;
  text-align: center;
}

.productLead {
  margin-top: 10px;
  max-width: 92ch;

  text-align: center;
  margin-left: auto;
  margin-right: auto;
}

.productBody {
  padding: 10px 2px 6px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.featureRow {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: start;
  gap: 16px;
  padding: 22px 22px;
  border: 0;
  /* border-radius: 18px; */
  background: #fff;
  box-shadow: 0 16px 42px rgba(2, 6, 23, 0.12);
  min-height: 178px;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease;
}

.featureRow:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 58px rgba(2, 6, 23, 0.16);
}

.featureDot {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: linear-gradient(180deg, #0766cd, #0d4a9e);
  box-shadow:
    0 10px 22px rgba(10, 71, 156, 0.25),
    inset 0 0 0 2px rgba(255, 255, 255, 0.85);
  margin-top: 4px;
}

.featureMain {
  min-width: 0;
}

.featureTitle {
  letter-spacing: -0.01em;
  color: rgba(2, 6, 23, 0.9);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.35;
}

.featureDesc {
  margin-top: 10px;
  line-height: 1.75;
  color: #666666;
  text-align: left;
}

.deliverTitle {
  font-weight: 900;
  margin-bottom: 6px;
}

@media (max-width: 960px) {
  .sectionHead {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .tabBar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .productBody {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .productBody {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tabBtn {
    transition: none !important;
    transform: none !important;
  }

  .tabText {
    transition: none !important;
  }

  .featureRow {
    transition: none !important;
    transform: none !important;
  }
}
</style>
