<script>
  import { darkMode } from '$lib/utils/stores.js';
  import { browser } from '$app/environment';

  export let title;
  export let subtitle;
  export let breadcrumb = [];

  const toggleTheme = () => {
    darkMode.toggle();
  };
</script>

<div class="bg-white dark:bg-gray-900 border-b border-gray-200 dark:border-gray-700 p-6 flex flex-col md:flex-row md:justify-between md:items-center">
  <div>
    <h1 class="text-2xl font-semibold text-gray-900 dark:text-gray-100">{title}</h1>
    {#if subtitle}
      <p class="text-gray-500 dark:text-gray-300 text-sm">{subtitle}</p>
    {/if}
  </div>
  <div class="flex items-center mt-2 md:mt-0 space-x-4">
    <slot name="extra" />
    <div class="flex items-center text-gray-500 dark:text-gray-300 text-sm">
      {#each breadcrumb as item, i}
        <span class="{item.active ? 'text-gray-900 dark:text-gray-100 font-medium' : ''}">{item.label}</span>
        {#if i < breadcrumb.length -1}
          <span class="mx-2">/</span>
        {/if}
      {/each}
    </div>
    <div class="flex items-center space-x-2">
      <button 
        class="p-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors duration-200" 
        on:click={toggleTheme}
        title={$darkMode ? 'Modo Claro' : 'Modo Escuro'}
      >
        {#if $darkMode}
          <svg class="w-5 h-5 text-yellow-500" fill="currentColor" viewBox="0 0 20 20">
            <path fill-rule="evenodd" d="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z" clip-rule="evenodd" />
          </svg>
        {:else}
          <svg class="w-5 h-5 text-gray-700 dark:text-gray-300" fill="currentColor" viewBox="0 0 20 20">
            <path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z" />
          </svg>
        {/if}
      </button>
    </div>
  </div>
</div>
