<script setup>
import { reactive } from "vue";
import { useRoute } from "vue-router";
import axios from "axios";
import moment from "moment";
import Navbar from "@/components/Navbar.vue";

const route = useRoute();
const newsId = route.params.id; // 網址參數
const news = reactive({
  data: [],
});

// 取得資料
(async function getData() {
  try {
    const response = await axios.get(
      `https://cmm.ai:8088/api/get_news?news_id=${newsId}`
    );
    news.data = response.data.news[0];
    console.log("news.data", news.data);
  } catch (error) {
    console.error(error);
  }
})();
</script>

<template>
  <Navbar />
  <div class="position-relative">
    <img src="@/assets/img/news/news-01.png" alt="" class="material-img" />
    <v-container class="pa-0 position-relative">
      <img
        src="@/assets/img/news/news-detail-banner.png"
        alt=""
        class="bg-img"
      />

      <div class="content">
        <v-row>
          <v-col cols="12">
            <div class="d-flex align-center mb-5">
              <v-chip size="large" variant="elevated" class="px-8 me-3">
                {{ news.data.category }}
              </v-chip>
              <p>
                {{ moment(`${news.data.create_time}`).format("YYYY.MM.DD") }}
              </p>
            </div>
            <h2>【{{ news.data.title }}】</h2>
            <img src="@/assets/img/img-04.jpg" alt="" class="cover-img" />
            <!-- <img :src="`https://cmm.ai/ntcri/${news.data.cover_img}`" alt="" /> -->
          </v-col>
          <v-col cols="12">
            <section class="h-100 d-flex flex-column pa-0">
              <p v-html="news.data.content"></p>
            </section>
          </v-col>
        </v-row>
      </div>

      <div class="btn-block">
        <v-btn rounded="xl" color="grey-darken-2" class="px-7">
          檔案下載
        </v-btn>
        <v-btn rounded="xl" color="grey-darken-2" class="px-7 ms-3">
          前往連結
        </v-btn>
      </div>
    </v-container>
    <router-link to="/news" class="mt-10 back-link"
      >＜ 返回最新消息</router-link
    >
    <img src="@/assets/img/news/news-01.png" alt="" class="material-img" />
  </div>
</template>

<style lang="scss" scoped>
.btn-block {
  position: absolute;
  bottom: 80px;
  right: 180px;
  @media (max-width: 600px) {
    bottom: 65px;
    right: unset;
    width: 100%;
    display: flex;
    justify-content: center;
  }
}
.content {
  position: absolute;
  right: 0;
  left: 0;
  top: 75px;
  height: 780px;
  overflow-y: scroll;
  overflow-x: hidden;
  display: flex;
  margin: auto;
  padding-top: 50px;
  justify-content: center;
  width: 75%;

  @media (max-width: 960px) {
    width: 80%;
  }

  @media (max-width: 600px) {
    top: 55px;
    height: 470px;
    padding-top: 10px;
  }

  h2 {
    margin: 40px auto;
    font-size: 28px;
    font-weight: 500;
    line-height: 38px;
    letter-spacing: 2px;
  }
  section {
    height: 100%;
    padding: 30px;
    p {
      padding: 20px;
      margin-bottom: 20px;
      font-size: 18px;
      font-weight: 400;
      line-height: 32px;
      letter-spacing: 1px;
    }
  }

  .cover-img {
    width: 100%;
    height: 500px;
    object-fit: cover;
    @media (max-width: 600px) {
      height: auto;
    }
  }
}
.bg-img {
  height: 1000px;
  position: relative;
  z-index: -1;
  @media (max-width: 600px) {
    height: 650px;
  }
}

.back-link {
  display: block;
  text-align: center;
  transition: all 0.3s;
  letter-spacing: 1px;

  &:hover {
    opacity: 0.8;
  }
}
.material-img {
  position: absolute;

  &:first-child {
    top: -15vw;
  }

  &:last-child {
    bottom: -150px;
    z-index: -5;
    transform: scaleX(-1);

    @media (max-width: 600px) {
      bottom: -50px;
    }
  }
}
</style>
