<template>
  <div class="not-found-container">
    <div class="not-found-content">
      <!-- 404 图标或动画 -->
      <!-- <div class="not-found-icon">
        <svg
          xmlns="http://www.w3.org/2000/svg"
          width="120"
          height="120"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
        >
          <circle cx="12" cy="12" r="10"></circle>
          <line x1="12" y1="8" x2="12" y2="12"></line>
          <line x1="12" y1="16" x2="12.01" y2="16"></line>
        </svg>
      </div> -->

      <!-- 标题和描述 -->
      <h1 class="not-found-title">404</h1>
      <h2 class="not-found-subtitle">页面未找到</h2>
      <p class="not-found-description">
        抱歉，您访问的页面不存在或已被移除。
        <br />
        请检查URL是否正确，或返回首页继续浏览。
      </p>

      <!-- 操作按钮 -->
      <div class="not-found-actions">
        <!-- <router-link to="/dataOverview" class="home-button">
          <span>返回首页</span>
        </router-link> -->
        <button @click="goHome" class="home-button">
          <span>返回首页</span>
        </button>
        <button @click="goBack" class="back-button">
          <span>返回上一页</span>
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from "vue-router";

import { storeToRefs } from "pinia";
import { useCounterStore } from "@/stores/index";

const router = useRouter();
const store = useCounterStore();
const { isCollapse, sidevarItem, roleList } = storeToRefs(store);
const goHome = () => {
  console.log(roleList);
  if (roleList.value.length) {
    router.push({
      path: roleList.value[0].path,
    });
  } else {
    router.push({
      path: "/login",
    });
  }
};

const goBack = () => {
  if (window.history.length > 1) {
    router.go(-1);
  } else {
    router.push("/");
  }
};
</script>

<style scoped lang="scss">
.not-found-container {
  width: 100%;
  height: 100vh;
  margin-right: 25%;
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  // justify-content: space-around;

  background-image: url("../../assets/img/404.png");
  /* 不重复平铺 */
  background-repeat: no-repeat;
  /* 背景图像充满整个页面 */
  // background-size: cover; /* 可选：使图像覆盖整个背景 */
  background-size: contain;
  /* 可选：设置背景图像的位置 */
  background-position: 30%; /* 居中 */
}

.not-found-content {
  text-align: center;
  max-width: 600px;
  padding: 40px;
  background-color: transparent;

  // border-radius: 12px;
  // box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.not-found-icon {
  margin-bottom: 24px;
}

.not-found-icon svg {
  color: #6c757d;
}

.not-found-title {
  font-size: 4rem;
  font-weight: 700;
  color: #343a40;
  margin: 0 0 10px;
}

.not-found-subtitle {
  font-size: 1.5rem;
  font-weight: 500;
  color: #495057;
  margin: 0 0 20px;
}

.not-found-description {
  font-size: 1rem;
  color: #6c757d;
  line-height: 1.6;
  margin-bottom: 30px;
}

.not-found-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.home-button,
.back-button {
  padding: 12px 24px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.home-button {
  background-color: #3b82f6;
  color: white;
  border: none;
}

.home-button:hover {
  background-color: #2563eb;
}

.back-button {
  background-color: white;
  color: #495057;
  border: 1px solid #dee2e6;
}

.back-button:hover {
  background-color: #f8f9fa;
  border-color: #ced4da;
}

@media (max-width: 600px) {
  .not-found-content {
    padding: 30px 20px;
  }

  .not-found-title {
    font-size: 3rem;
  }

  .not-found-subtitle {
    font-size: 1.25rem;
  }

  .not-found-actions {
    flex-direction: column;
    gap: 12px;
  }

  .home-button,
  .back-button {
    width: 100%;
    justify-content: center;
  }
}
</style>
