---
import config from 'virtual:starlight/user-config';

import Search from 'virtual:starlight/components/Search';
import SiteTitle from 'virtual:starlight/components/SiteTitle';

const shouldRenderSearch =
	config.pagefind || config.components.Search !== '@astrojs/starlight/components/Search.astro';
---

<div class="header">
	<div class="title-wrapper sl-flex">
		<SiteTitle />
	</div>
	<div class="sl-flex print:hidden">
		{shouldRenderSearch && <Search />}
	</div>
	<div class="sl-hidden md:sl-flex print:hidden right-group">
		<a href="/changelog" class="nav-link">
			Changelog
		</a>
		<a href="https://dashboard.butterbase.ai" class="login-btn">
			Log In
		</a>
	</div>
</div>

<style>
	@layer starlight.core {
		.header {
			display: flex;
			gap: var(--sl-nav-gap);
			justify-content: space-between;
			align-items: center;
			height: 100%;
		}

		.title-wrapper {
			overflow: clip;
			padding: 0.25rem;
			margin: -0.25rem;
			min-width: 0;
		}

		.right-group {
			gap: 1rem;
			align-items: center;
		}

		.login-btn {
			display: inline-flex;
			align-items: center;
			gap: 0.375rem;
			padding: 0.4rem 1rem;
			border-radius: 0.375rem;
			font-size: 0.8125rem;
			font-weight: 600;
			text-decoration: none;
			background: hsl(43 82% 46%);
			color: hsl(35 48% 8%);
			transition: background 0.15s ease, transform 0.1s ease;
			white-space: nowrap;
		}

		.login-btn:hover {
			background: hsl(43 82% 52%);
			transform: translateY(-1px);
			color: hsl(35 48% 8%);
		}

		.nav-link {
			display: inline-flex;
			align-items: center;
			font-size: 0.8125rem;
			font-weight: 600;
			text-decoration: none;
			color: var(--sl-color-text);
			transition: color 0.15s ease;
			white-space: nowrap;
		}

		.nav-link:hover {
			color: var(--sl-color-text-accent);
		}

		@media (min-width: 50rem) {
			:global(:root[data-has-sidebar]) {
				--__sidebar-pad: calc(2 * var(--sl-nav-pad-x));
			}
			:global(:root:not([data-has-toc])) {
				--__toc-width: 0rem;
			}
			.header {
				--__sidebar-width: max(0rem, var(--sl-content-inline-start, 0rem) - var(--sl-nav-pad-x));
				--__main-column-fr: calc(
					(
							100% + var(--__sidebar-pad, 0rem) - var(--__toc-width, var(--sl-sidebar-width)) -
								(2 * var(--__toc-width, var(--sl-nav-pad-x))) - var(--sl-content-inline-start, 0rem) -
								var(--sl-content-width)
						) / 2
				);
				display: grid;
				grid-template-columns:
					minmax(
						calc(var(--__sidebar-width) + max(0rem, var(--__main-column-fr) - var(--sl-nav-gap))),
						auto
					)
					1fr
					auto;
				align-content: center;
			}
		}
	}
</style>
