<template>
  <header></header>
  <main class="p-[35px] max-w-[1200px] mx-auto">
    <div class="title mb-[20px]">
      {{ t("financialinformation.quarterlyreports.title") }}
    </div>
    <div class="search-container">
      <input
        type="text"
        :placeholder="
          t('financialinformation.quarterlyreports.search.placeholder')
        "
        v-model="searchQuery"
        class="search-input"
      />
      <button class="search-button" @click="handleSearch">
        {{ t("financialinformation.quarterlyreports.search.button") }}
      </button>
    </div>

    <div class="results-list">
      <div
        v-for="(item, index) in filteredList"
        :key="index"
        class="result-item"
      >
        <div class="content">
          <p class="result-title subtitle">{{ item.title }}</p>
          <p class="result-description content-text">{{ item.description }}</p>
        </div>

        <div
          class="pdf-icon"
          @click="downloadPdf(item.url)"
          style="color: #2979ff; cursor: pointer"
        >
          <img src="@/assets/image/pdf.png" alt="PDF" />
          {{ t("financialinformation.quarterlyreports.download") }}
        </div>
      </div>
    </div>
  </main>
  <footer></footer>
</template>
<script setup>
import { ref, watch, onMounted, computed, reactive } from "vue";
import { useI18n } from "vue-i18n";
import quarterlyPdf2024Q3 from "@/assets/file/quarterly/10Q 2024-Q3.pdf";
import quarterlyPdf2024Q2 from "@/assets/file/quarterly/10Q 2024-Q2.pdf";
import quarterlyPdf2024Q1 from "@/assets/file/quarterly/10Q 2024-Q1.pdf";
import quarterlyPdf2023Q3 from "@/assets/file/quarterly/10Q 2023-Q3.pdf";
import quarterlyPdf2023Q2 from "@/assets/file/quarterly/10Q 2023-Q2.pdf";
import quarterlyPdf2023Q1 from "@/assets/file/quarterly/10Q 2023-Q1.pdf";
import quarterlyPdf2022Q3 from "@/assets/file/quarterly/10Q 2022-Q3.pdf";
import quarterlyPdf2022Q2 from "@/assets/file/quarterly/10Q 2022-Q2.pdf";
import quarterlyPdf2022Q1 from "@/assets/file/quarterly/10Q 2022-Q1.pdf";
import quarterlyPdf2021Q3 from "@/assets/file/quarterly/10Q 2021-Q3.pdf";
import quarterlyPdf2021Q2 from "@/assets/file/quarterly/10Q 2021-Q2.pdf";
import quarterlyPdf2021Q1 from "@/assets/file/quarterly/10Q 2021-Q1.pdf";
import quarterlyPdf2020Q3 from "@/assets/file/quarterly/10Q 2020-Q3.pdf";
import quarterlyPdf2020Q2 from "@/assets/file/quarterly/10Q 2020-Q2.pdf";
import quarterlyPdf2020Q1 from "@/assets/file/quarterly/10Q 2020-Q1.pdf";
import quarterlyPdf2019Q3 from "@/assets/file/quarterly/10Q 2019-Q3.pdf";
import quarterlyPdf2019Q2 from "@/assets/file/quarterly/10Q 2019-Q2.pdf";
import quarterlyPdf2019Q1 from "@/assets/file/quarterly/10Q 2019-Q1.pdf";
import quarterlyPdf2018Q3 from "@/assets/file/quarterly/10Q 2018-Q3.pdf";
import quarterlyPdf2018Q2 from "@/assets/file/quarterly/10Q 2018-Q2.pdf";
import quarterlyPdf2018Q1 from "@/assets/file/quarterly/10Q 2018-Q1.pdf";
import quarterlyPdf2017Q3 from "@/assets/file/quarterly/10Q 2017-Q3.pdf";
import quarterlyPdf2017Q2 from "@/assets/file/quarterly/10Q 2017-Q2.pdf";
import quarterlyPdf2017Q1 from "@/assets/file/quarterly/10Q 2017-Q1.pdf";
import quarterlyPdf2016Q3 from "@/assets/file/quarterly/10Q 2016-Q3.pdf";
import quarterlyPdf2016Q2 from "@/assets/file/quarterly/10Q 2016-Q2.pdf";
import quarterlyPdf2016Q1 from "@/assets/file/quarterly/10Q 2016-Q1.pdf";
import quarterlyPdf2015Q3 from "@/assets/file/quarterly/10Q 2015-Q3.pdf";
import quarterlyPdf2015Q2 from "@/assets/file/quarterly/10Q 2015-Q2.pdf";
import quarterlyPdf2015Q1 from "@/assets/file/quarterly/10Q 2015-Q1.pdf";
import quarterlyPdf2014Q3 from "@/assets/file/quarterly/10Q 2014-Q3.pdf";
import quarterlyPdf2014Q2 from "@/assets/file/quarterly/10Q 2014-Q2.pdf";
import quarterlyPdf2014Q1 from "@/assets/file/quarterly/10Q 2014-Q1.pdf";
import quarterlyPdf2013Q3 from "@/assets/file/quarterly/10Q 2013-Q3.pdf";
import quarterlyPdf2013Q2 from "@/assets/file/quarterly/10Q 2013-Q2.pdf";
import quarterlyPdf2013Q1 from "@/assets/file/quarterly/10Q 2013-Q1.pdf";
import quarterlyPdf2012Q3 from "@/assets/file/quarterly/10Q 2012-Q3.pdf";
import quarterlyPdf2012Q2 from "@/assets/file/quarterly/10Q 2012-Q2.pdf";
import quarterlyPdf2012Q1 from "@/assets/file/quarterly/10Q 2012-Q1.pdf";
import quarterlyPdf2011Q3 from "@/assets/file/quarterly/10Q 2011-Q3.pdf";
import quarterlyPdf2011Q2 from "@/assets/file/quarterly/10Q 2011-Q2.pdf";
import quarterlyPdf2011Q1 from "@/assets/file/quarterly/10Q 2011-Q1.pdf";
import quarterlyPdf2010Q3 from "@/assets/file/quarterly/10Q 2010-Q3.pdf";
import quarterlyPdf2010Q2 from "@/assets/file/quarterly/10Q 2010-Q2.pdf";
import quarterlyPdf2010Q1 from "@/assets/file/quarterly/10Q 2010-Q1.pdf";
import quarterlyPdf2009Q3 from "@/assets/file/quarterly/10Q 2009-Q3.pdf";

const { t } = useI18n();
const searchQuery = ref("");

const state = reactive({
  list: [
    {
      title: "2024 Q3 Quarterly Reports",
      description: "Third Quarter 2024 Financial Results",
      url: quarterlyPdf2024Q3,
    },
    {
      title: "2024 Q2 Quarterly Reports",
      description: "Second Quarter 2024 Financial Results",
      url: quarterlyPdf2024Q2,
    },
    {
      title: "2024 Q1 Quarterly Reports",
      description: "First Quarter 2024 Financial Results",
      url: quarterlyPdf2024Q1,
    },
    {
      title: "2023 Q3 Quarterly Reports",
      description: "Third Quarter 2023 Financial Results",
      url: quarterlyPdf2023Q3,
    },
    {
      title: "2023 Q2 Quarterly Reports",
      description: "Second Quarter 2023 Financial Results",
      url: quarterlyPdf2023Q2,
    },
    {
      title: "2023 Q1 Quarterly Reports",
      description: "First Quarter 2023 Financial Results",
      url: quarterlyPdf2023Q1,
    },
    {
      title: "2022 Q3 Quarterly Reports",
      description: "Third Quarter 2022 Financial Results",
      url: quarterlyPdf2022Q3,
    },
    {
      title: "2022 Q2 Quarterly Reports",
      description: "Second Quarter 2022 Financial Results",
      url: quarterlyPdf2022Q2,
    },
    {
      title: "2022 Q1 Quarterly Reports",
      description: "First Quarter 2022 Financial Results",
      url: quarterlyPdf2022Q1,
    },
    {
      title: "2021 Q3 Quarterly Reports",
      description: "Third Quarter 2021 Financial Results",
      url: quarterlyPdf2021Q3,
    },
    {
      title: "2021 Q2 Quarterly Reports",
      description: "Second Quarter 2021 Financial Results",
      url: quarterlyPdf2021Q2,
    },
    {
      title: "2021 Q1 Quarterly Reports",
      description: "First Quarter 2021 Financial Results",
      url: quarterlyPdf2021Q1,
    },
    {
      title: "2020 Q3 Quarterly Reports",
      description: "Third Quarter 2020 Financial Results",
      url: quarterlyPdf2020Q3,
    },
    {
      title: "2020 Q2 Quarterly Reports",
      description: "Second Quarter 2020 Financial Results",
      url: quarterlyPdf2020Q2,
    },
    {
      title: "2020 Q1 Quarterly Reports",
      description: "First Quarter 2020 Financial Results",
      url: quarterlyPdf2020Q1,
    },
    {
      title: "2019 Q3 Quarterly Reports",
      description: "Third Quarter 2019 Financial Results",
      url: quarterlyPdf2019Q3,
    },
    {
      title: "2019 Q2 Quarterly Reports",
      description: "Second Quarter 2019 Financial Results",
      url: quarterlyPdf2019Q2,
    },
    {
      title: "2019 Q1 Quarterly Reports",
      description: "First Quarter 2019 Financial Results",
      url: quarterlyPdf2019Q1,
    },
    {
      title: "2018 Q3 Quarterly Reports",
      description: "Third Quarter 2018 Financial Results",
      url: quarterlyPdf2018Q3,
    },
    {
      title: "2018 Q2 Quarterly Reports",
      description: "Second Quarter 2018 Financial Results",
      url: quarterlyPdf2018Q2,
    },
    {
      title: "2018 Q1 Quarterly Reports",
      description: "First Quarter 2018 Financial Results",
      url: quarterlyPdf2018Q1,
    },
    {
      title: "2017 Q3 Quarterly Reports",
      description: "Third Quarter 2017 Financial Results",
      url: quarterlyPdf2017Q3,
    },
    {
      title: "2017 Q2 Quarterly Reports",
      description: "Second Quarter 2017 Financial Results",
      url: quarterlyPdf2017Q2,
    },
    {
      title: "2017 Q1 Quarterly Reports",
      description: "First Quarter 2017 Financial Results",
      url: quarterlyPdf2017Q1,
    },
    {
      title: "2016 Q3 Quarterly Reports",
      description: "Third Quarter 2016 Financial Results",
      url: quarterlyPdf2016Q3,
    },
    {
      title: "2016 Q2 Quarterly Reports",
      description: "Second Quarter 2016 Financial Results",
      url: quarterlyPdf2016Q2,
    },
    {
      title: "2016 Q1 Quarterly Reports",
      description: "First Quarter 2016 Financial Results",
      url: quarterlyPdf2016Q1,
    },
    {
      title: "2015 Q3 Quarterly Reports",
      description: "Third Quarter 2015 Financial Results",
      url: quarterlyPdf2015Q3,
    },
    {
      title: "2015 Q2 Quarterly Reports",
      description: "Second Quarter 2015 Financial Results",
      url: quarterlyPdf2015Q2,
    },
    {
      title: "2015 Q1 Quarterly Reports",
      description: "First Quarter 2015 Financial Results",
      url: quarterlyPdf2015Q1,
    },
    {
      title: "2014 Q3 Quarterly Reports",
      description: "Third Quarter 2014 Financial Results",
      url: quarterlyPdf2014Q3,
    },
    {
      title: "2014 Q2 Quarterly Reports",
      description: "Second Quarter 2014 Financial Results",
      url: quarterlyPdf2014Q2,
    },
    {
      title: "2014 Q1 Quarterly Reports",
      description: "First Quarter 2014 Financial Results",
      url: quarterlyPdf2014Q1,
    },
    {
      title: "2013 Q3 Quarterly Reports",
      description: "Third Quarter 2013 Financial Results",
      url: quarterlyPdf2013Q3,
    },
    {
      title: "2013 Q2 Quarterly Reports",
      description: "Second Quarter 2013 Financial Results",
      url: quarterlyPdf2013Q2,
    },
    {
      title: "2013 Q1 Quarterly Reports",
      description: "First Quarter 2013 Financial Results",
      url: quarterlyPdf2013Q1,
    },
    {
      title: "2012 Q3 Quarterly Reports",
      description: "Third Quarter 2012 Financial Results",
      url: quarterlyPdf2012Q3,
    },
    {
      title: "2012 Q2 Quarterly Reports",
      description: "Second Quarter 2012 Financial Results",
      url: quarterlyPdf2012Q2,
    },
    {
      title: "2012 Q1 Quarterly Reports",
      description: "First Quarter 2012 Financial Results",
      url: quarterlyPdf2012Q1,
    },
    {
      title: "2011 Q3 Quarterly Reports",
      description: "Third Quarter 2011 Financial Results",
      url: quarterlyPdf2011Q3,
    },
    {
      title: "2011 Q2 Quarterly Reports",
      description: "Second Quarter 2011 Financial Results",
      url: quarterlyPdf2011Q2,
    },
    {
      title: "2011 Q1 Quarterly Reports",
      description: "First Quarter 2011 Financial Results",
      url: quarterlyPdf2011Q1,
    },
    {
      title: "2010 Q3 Quarterly Reports",
      description: "Third Quarter 2010 Financial Results",
      url: quarterlyPdf2010Q3,
    },
    {
      title: "2010 Q2 Quarterly Reports",
      description: "Second Quarter 2010 Financial Results",
      url: quarterlyPdf2010Q2,
    },
    {
      title: "2010 Q1 Quarterly Reports",
      description: "First Quarter 2010 Financial Results",
      url: quarterlyPdf2010Q1,
    },
    {
      title: "2009 Q3 Quarterly Reports",
      description: "Third Quarter 2009 Financial Results",
      url: quarterlyPdf2009Q3,
    },
  ],
});

onMounted(async () => {});
const filteredList = computed(() => {
  if (!searchQuery.value) return state.list;
  const query = searchQuery.value.toLowerCase();
  return state.list.filter(
    (item) =>
      item.title.toLowerCase().includes(query) ||
      item.description.toLowerCase().includes(query)
  );
});

const handleSearch = () => {
  // 搜索处理逻辑
  console.log("搜索:", searchQuery.value);
};
const downloadPdf = async (pdfResource, filename = "") => {
  try {
    // 获取PDF文件
    const response = await fetch(pdfResource);
    const blob = await response.blob();

    // 创建Blob URL
    const blobUrl = URL.createObjectURL(blob);

    // 创建下载链接
    const a = document.createElement("a");
    a.href = blobUrl;
    a.download = filename || pdfResource.split("/").pop() || "download.pdf";

    // 触发下载
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);

    // 释放Blob URL
    URL.revokeObjectURL(blobUrl);
  } catch (error) {
    console.error("下载PDF文件失败:", error);
  }
};
</script>
<style scoped lang="scss">
.title {
  font-size: 40px;
  color: #333;
}
.subtitle {
  font-size: 18px;
  font-weight: 600;
  color: #333;
}
.content-text {
  font-size: 16px;
}
.search-container {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
}

.search-input {
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  width: 360px;
  margin-right: 10px;
}

.search-button {
  padding: 8px 16px;
  background-color: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
}

.results-list {
  padding-right: 20px;
  margin-top: 20px;
  max-height: 1200px;
  overflow-y: auto;
}

.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid #eee;
}

.content {
  flex: 1;
}

.result-title {
  color: #0078d7;
  text-decoration: none;
  display: block;
  margin-bottom: 5px;
}

.result-description {
  color: #666;
  margin: 0;
}

.pdf-icon {
  margin-left: 15px;

  img {
    width: 24px;
    height: 24px;
  }
}
</style>
