---
import '@fontsource-variable/assistant';
import '@fontsource/frank-ruhl-libre/hebrew-300.css';
import '@fontsource/frank-ruhl-libre/latin-300.css';
import '../styles/global.css';
import Header from '../components/Header.astro';
import Footer from '../components/Footer.astro';
import A11yMenu from '../components/A11yMenu.astro';
import Icon from '../components/Icon.astro';
import { getSettings } from '../lib/content';
import { imageUrl, type ImageValue } from '../lib/image';

interface Props {
  title?: string;
  description?: string;
  image?: ImageValue;
  type?: 'website' | 'article';
  jsonLd?: Record<string, unknown>;
  noindex?: boolean;
}
const { title, description, image, type = 'website', jsonLd, noindex } = Astro.props;
const settings = await getSettings();
const siteName = `${settings.title} | ${settings.ownerName}`;
const fullTitle = title ? `${title} | ${settings.title} – ${settings.ownerName}` : `${siteName} – ${settings.tagline}`;
const metaDescription = description || settings.description;
const canonical = new URL(Astro.url.pathname, Astro.site);
const ogImage = new URL(imageUrl(image, 1200, 630) || '/images/shani-flowers.webp', Astro.site);
---
<!doctype html>
<html lang="he" dir="rtl" class="no-js">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>{fullTitle}</title>
    <meta name="description" content={metaDescription} />
    <link rel="canonical" href={canonical} />
    {noindex && <meta name="robots" content="noindex" />}
    <meta name="theme-color" content="#fcfcff" />
    <link rel="icon" type="image/png" href="/images/favicon.png" />
    <link rel="apple-touch-icon" href="/images/apple-touch-icon.png" />
    <link rel="sitemap" href="/sitemap.xml" />

    <meta property="og:type" content={type} />
    <meta property="og:locale" content="he_IL" />
    <meta property="og:site_name" content={siteName} />
    <meta property="og:title" content={title ?? siteName} />
    <meta property="og:description" content={metaDescription} />
    <meta property="og:url" content={canonical} />
    <meta property="og:image" content={ogImage} />
    <meta name="twitter:card" content="summary_large_image" />

    {jsonLd && <script type="application/ld+json" set:html={JSON.stringify(jsonLd)} />}

    <script is:inline>
      document.documentElement.classList.remove('no-js');
      try {
        var s = JSON.parse(localStorage.getItem('shanina-a11y') || 'null');
        if (s) {
          var sizes = [1, 1.125, 1.25, 1.4];
          document.documentElement.style.setProperty('--text-scale', sizes[s.size] || 1);
          for (var k in s.flags) document.documentElement.dataset[k] = s.flags[k];
        }
      } catch (e) {}
    </script>
  </head>
  <body>
    <a class="skip-link" href="#main">דילוג לתוכן</a>
    <Header settings={settings} />
    <main id="main" tabindex="-1">
      <slot />
    </main>
    <Footer settings={settings} />
    <aside aria-label="פעולות מהירות">
      <A11yMenu />
      <a class="float-wa" href={settings.whatsappUrl} target="_blank" rel="noopener" aria-label="שליחת הודעה בוואטסאפ">
        <Icon name="whatsapp" size={28} />
      </a>
    </aside>

    <script>
      const io = new IntersectionObserver(
        (entries) => entries.forEach((e) => { if (e.isIntersecting) { e.target.classList.add('is-visible'); io.unobserve(e.target); } }),
        { rootMargin: '0px 0px -8% 0px' },
      );
      document.querySelectorAll('.reveal').forEach((el) => io.observe(el));
    </script>

    <style>
      .float-wa {
        position: fixed; inset-inline-start: 16px; bottom: 16px; z-index: 60;
        width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
        background: #1fa855; color: #fff; box-shadow: 0 12px 26px -10px rgb(20 110 60 / 0.7);
        transition: transform 0.25s var(--ease);
      }
      .float-wa:hover { color: #fff; transform: scale(1.06); }
      main:focus { outline: none; }
    </style>
  </body>
</html>
