<template>
  <div class="drive-page">
    <Header />

    <main class="drive-main">
      <section class="drive-hero">
        <div class="drive-hero__copy">
          <p class="drive-hero__eyebrow">DASHBOARD PORTAL</p>
          <p class="drive-hero__title">驾驶舱门户</p>
          <p class="drive-hero__desc">选择一个驾驶舱，快速进入对应业务看板。</p>
        </div>
        <div class="drive-hero__visual">
          <el-image :src="banner" class="drive-hero__image" />
        </div>
      </section>

      <section class="drive-tabs px-10">
        <button type="button" class="drive-tab drive-tab--active">
          全部驾驶舱
        </button>
        <button type="button" class="drive-tab">经营管理</button>
        <button type="button" class="drive-tab">生产运营</button>
        <button type="button" class="drive-tab">财务管理</button>
        <button type="button" class="drive-tab">供应链管理</button>
        <button type="button" class="drive-tab">市场营销</button>
        <button type="button" class="drive-tab">QHSE</button>
      </section>

      <section class="drive-grid md:px-20">
        <button
          v-for="card in driveCards"
          :key="card.title"
          type="button"
          class="drive-card overflow-hidden"
          @click="openDrive(card)"
        >
          <!-- <div>
            <el-image :src="dr1"></el-image>
          </div> -->
        </button>
      </section>
    </main>

    <div class="mt-[500px] md:mt-[300px]">
      <Footer />
    </div>
  </div>
</template>

<script setup lang="ts">
import Header from "@components/home/header.vue";
import Footer from "@components/home/Footer.vue";
import { Icon } from "@iconify/vue";

import { getMCSsoToken } from "@/api/user";
import { useUserStore } from "@/stores/useUserStore";
import { getAccessToken } from "@/utils/auth";
import banner from "@/assets/images/drivebannere.png";
import dr from "@/assets/images/dr.png";
import moblie from "@/assets/images/mobile.png";
import pruduct from "@/assets/images/生产驾驶舱.png";
import chain from "@/assets/images/供应链驾驶舱.png";
import money from "@/assets/images/财务驾驶舱.png";
import market from "@/assets/images/市场驾驶舱.png";
import qhse from "@/assets/images/QHSE驾驶舱.png";

const userStore = useUserStore();

type DriveCard = {
  title: string;
  description: string;
  icon: string;
  url: string;
  bgColor: string;
};

const driveCards: DriveCard[] = [
  {
    title: "经营驾驶舱",
    description: "查看经营分析、经营指标与执行情况。",
    icon: moblie,
    url: "https://report.deepoil.cc/webroot/decision/v10/entry/access/9fb42908-894a-4373-a6be-ce046a42851d?preview=true&page_number=1",
    bgColor: "#3876e0",
  },
  {
    title: "生产驾驶舱",
    description: "查看生产运营态势、核心指标与执行情况。",
    icon: pruduct,
    url: "https://report.deepoil.cc/webroot/decision/v10/entry/access/dbc9cf73-81ce-43f1-9923-45cdfa5d5d3a?preview=true&page_number=1",
    bgColor: "#0f766e",
  },
  {
    title: "财务驾驶舱",
    description: "查看财务分析、预算执行与经营数据表现。",
    icon: money,
    url: "https://report.deepoil.cc/webroot/decision/v10/entry/access/e836fb5b-092c-4d64-a324-3beeb4fac0cc?preview=true&page_number=1",
    bgColor: "#ca8a04",
  },

  {
    title: "供应链驾驶舱",
    description: "查看供应链分析、物料需求与执行。",
    icon: chain,
    url: "#",
    bgColor: "#7c3aed",
  },

  // 市场驾驶舱
  {
    title: "市场驾驶舱",
    description: "查看市场分析、销售数据与执行情况。",
    icon: market,
    url: "#",
    bgColor: "#16a34a",
  },

  // QHSE驾驶舱
  {
    title: "QHSE驾驶舱",
    description: "查看安全、健康、环境与质量数据。",
    icon: qhse,
    url: "#",
    bgColor: "#dc2626",
  },
];

const openDrive = async (option: DriveCard) => {
  if (userStore.getUser.username && getAccessToken()) {
    const res = await getMCSsoToken();
    if (res) {
      window.open(`${option.url}&ssoToken=${res}`, "_blank");
    }
  }
};
</script>

<style scoped>
.drive-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 0%, rgba(30, 74, 255, 0.18), transparent 28%),
    radial-gradient(
      circle at 82% 18%,
      rgba(151, 66, 255, 0.16),
      transparent 18%
    ),
    linear-gradient(180deg, #000613 0%, #000613 100%);
}

.drive-main {
  max-width: 100vw;
  margin: 0 auto;
  padding-top: 50px;
}

.drive-hero {
  position: relative;
  min-height: 340px;

  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(2, 8, 25, 0.55), rgba(2, 8, 25, 0.86)), #000613;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.drive-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    rgba(0, 6, 19, 0.8) 0%,
    rgba(0, 6, 19, 0.24) 40%,
    rgba(0, 6, 19, 0.08) 100%
  );
  z-index: 1;
}

.drive-hero__copy {
  position: absolute;
  z-index: 2;
  left: 56px;
  top: 54px;
  max-width: 560px;
}

.drive-hero__eyebrow {
  margin: 0 0 16px;
  color: #6d77ff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.22em;
}

.drive-hero__title {
  margin: 0;
  color: #f5f8ff;
  font-size: clamp(20px, 5vw, 50px);
  font-weight: 900;
  line-height: 1.08;
  text-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}

.drive-hero__desc {
  margin: 20px 0 0;
  color: #5c6dc8;
  font-size: 18px;
  line-height: 1.8;
}

.drive-hero__visual {
  position: absolute;
  inset: 0;
}

.drive-hero__image {
  width: 100%;
  height: 100%;
}

.drive-hero__image :deep(img) {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(1.1) contrast(1.05);
}

.drive-tabs {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0;
  margin: 0 auto;
  padding: 12px 18px;
  width: 90%;
  border: 1px solid rgba(79, 110, 208, 0.16);
  border-radius: 10px;
  background: rgba(8, 14, 30, 0.86);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.2);
}

.drive-tab {
  height: 58px;
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  background: transparent;
  color: rgba(220, 229, 255, 0.78);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.drive-tab:last-child {
  border-right: 0;
}

.drive-tab--active {
  color: #fff;
  position: relative;
}

.drive-tab--active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -12px;
  width: 72px;
  height: 4px;
  border-radius: 999px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #8f65ff 0%, #4d82ff 100%);
  box-shadow: 0 0 18px rgba(97, 111, 255, 0.85);
}

.drive-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
  margin-top: 30px;
}

.drive-card {
  position: relative; /* 确保内部绝对定位元素参考此容器 */
  display: flex;
  align-items: center; /* 垂直居中文字 */
  justify-content: center; /* 水平居中文字 */

  width: 100%;
  height: 184px; /* 固定高度 */

  /* 背景图设置 */
  background-image: url("@/assets/images/dr1.png"); /* 注意：在 style 中引用静态资源可能需要 ~@ 或直接路径，Vite/Vue3通常支持 @ */
  background-size: contain; /* 关键：覆盖整个区域，裁剪多余部分，无间距 */
  background-position: center; /* 关键：居中显示 */
  background-repeat: no-repeat;

  text-align: center;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease;

  overflow: hidden;
  margin-top: -50px;
}

.drive-card:hover {
  transform: translateY(-4px);
  border-color: rgba(115, 145, 255, 0.42);
  box-shadow: 0 28px 54px rgba(0, 0, 0, 0.42);
}

.drive-card__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 120px;
  border-radius: 22px;
  color: #fff;
  font-size: 42px;
  flex-shrink: 0;
}

.drive-card__content {
  min-width: 0;
  flex: 1;
}

.drive-card__title {
  margin: 0;
  color: #f4f7ff;
  font-size: 28px;
  font-weight: 700;
}

.drive-card__text {
  margin: 10px 0 0;
  color: rgba(191, 203, 235, 0.82);
  font-size: 16px;
  line-height: 1.7;
}

.drive-card__arrow {
  color: rgba(210, 220, 248, 0.82);
  font-size: 34px;
  flex-shrink: 0;
  transition:
    transform 0.2s ease,
    color 0.2s ease;
}

.drive-card:hover .drive-card__arrow {
  color: #ffffff;
  transform: translate(2px, -2px);
}

@media (max-width: 768px) {
  .drive-main {
    padding: 50px 0px 56px;
    margin-top: 0;
  }

  .drive-hero {
    min-height: 260px;
  }

  .drive-hero__copy {
    left: 20px;
    right: 20px;
    top: 24px;
  }

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

  .drive-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    padding-left: 0;
  }

  .drive-card {
    min-height: 100px;
    height: 0px;
    width: 100vw;
    padding: 0;
    margin-top: 0;

    /* padding: 22px 18px; */
    background-image: url("@/assets/images/mobile.png");
    background-size: contain;
    background-position: center center;
  }

  /* .drive-card__icon {
    width: 88px;
    height: 88px;
  } */

  .drive-card__title {
    font-size: 20px;
  }

  .drive-hero__image :deep(img) {
    object-fit: cover;
    object-position: 68% center;
  }
}
</style>
