<script lang="ts">
  import Header from '../../lib/components/layout/Header.svelte';
  import DiscussionList from '../../lib/modules/discussions/DiscussionList.svelte';
  import SearchBox from '../../lib/components/layout/SearchBox.svelte';
  import { nostrClient } from '../../lib/services/nostr/nostr-client.js';
  import { onMount } from 'svelte';

  onMount(async () => {
    await nostrClient.initialize();
  });
</script>

<Header />

<main class="container mx-auto px-4 py-8">
  <div class="discussions-content">
    <div class="discussions-header mb-4">
      <div>
        <h1 class="text-2xl font-bold mb-6 text-fog-text dark:text-fog-dark-text font-mono">/Discussions</h1>
        <p class="mb-4 text-fog-text dark:text-fog-dark-text">Decentralized discussion board on Nostr.</p>
      </div>
      <a href="/write?kind=11" class="write-button" title="Write a new thread">
        <span class="emoji emoji-grayscale">✍️</span>
      </a>
    </div>

    <div class="search-section mb-6">
      <SearchBox />
    </div>

    <DiscussionList />
  </div>
</main>

<style>
  .discussions-content {
    max-width: var(--content-width);
    margin: 0 auto;
  }

  .discussions-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0 1rem;
  }

  .search-section {
    padding: 0 1rem;
  }
</style>
