---
import Layout from "../../layouts/Layout.astro";
import { getCollection } from "astro:content";
import { getCategory } from "../../utils/notes";
import NotesSearch from "../../components/NotesSearch.svelte";

const notes = await getCollection("notes");
const sortedNotes = notes.sort(
  (a, b) => b.data.publishDate.getTime() - a.data.publishDate.getTime(),
);

const searchNotes = sortedNotes.map((n) => ({
  id: n.id,
  title: n.data.title,
  description: n.data.description,
  tags: n.data.tags,
  category: getCategory(n),
  searchText: [n.data.title, n.data.description, n.body ?? ""]
    .join(" ")
    .toLowerCase(),
}));
---

<Layout
  title="Infosec Notes - Another Hadi"
  description="Cheatsheets on cybersecurity tools and techniques."
>
  <main class="max-w-4xl mx-auto px-4 py-16 sm:py-20">
    <div class="text-center mb-12">
      <h1 class="text-4xl sm:text-5xl font-bold mb-4">Infosec Notes</h1>
      <p class="text-xl text-base-content/70">
        Cheat sheets on cybersecurity tools and techniques.
      </p>
    </div>
    <div
      class="text-xs font-mono text-base-content/25 border border-base-300/30 rounded-box px-4 py-3 mb-10 max-w-xl mx-auto text-center leading-relaxed"
    >
      All content is intended for educational purposes, CTF challenges, and
      authorized penetration testing only. Do not use any of this against
      systems you do not own or have explicit permission to test.
    </div>
    <NotesSearch client:load notes={searchNotes} />
  </main>
</Layout>
