---
import { createClient } from '@/lib/pocketbase';

const { width = 50, height = 30, className = '' } = Astro.props;

// Получаем данные из коллекции site_settings
const pb = createClient(Astro);
const records = await pb.collection('site_settings').getList(1, 1, {
  sort: '-created'  // Берём самую последнюю запись
});

const siteSettings = records.items[0] || {};
const logoPath = siteSettings.site_logo
  ? `${pb.baseURL}/api/files/site_settings/${siteSettings.id}/${siteSettings.site_logo}`
  : null;
---

{logoPath ? (
  <a href="/" aria-label="Zur Startseite wechseln">
    <div class={`relative flex items-center justify-start ${className}`}>
      <img
        src={logoPath}
        alt="MinivanBerlin Logo"
        width={width}
        height={height}
        class="object-contain object-left max-w-full"
      />
    </div>
  </a>
) : (
  // Можно добавить placeholder элемент, если логотип не установлен
  <div class={`relative flex items-center justify-start ${className}`}>
    <div class="text-gray-400 italic" style={`width: ${width}px; height: ${height}px; display: flex; align-items: center; justify-content: center;`}>
      Logo
    </div>
  </div>
)}