@props(['variant' => 'primary', 'href' => null, 'type' => 'button', 'size' => 'md', 'navigate' => true])
@php
// Text colours are forced (!) because the base style colours every with the link colour.
$base = 'touch inline-flex items-center justify-center gap-2 rounded-xl text-center font-semibold no-underline transition active:scale-[0.98] disabled:opacity-60 disabled:pointer-events-none';
$sizes = ['md' => 'px-5 py-2.5 text-base', 'sm' => 'px-3 py-1.5 text-sm', 'lg' => 'px-6 py-3 text-lg'];
$variants = [
'primary' => 'bg-turquoise !text-navy hover:brightness-95 shadow-sm',
'secondary' => 'bg-navy !text-white hover:bg-[#0a3d7a] dark:bg-surface dark:!text-ink dark:ring-1 dark:ring-line',
'ghost' => '!text-ink hover:bg-surface-alt ring-1 ring-field',
'danger' => 'bg-bad !text-[#7a1020] hover:brightness-95',
];
// The spinner and the disabled state only follow the request this button starts (never the autosave of a neighbouring field).
$target = $attributes->get('wire:target') ?: (preg_match('/^\$?([A-Za-z_]+)/', (string) $attributes->get('wire:click'), $m) ? $m[1] : null);
$class = $base.' '.($sizes[$size] ?? $sizes['md']).' '.($variants[$variant] ?? $variants['primary']);
@endphp
@if ($href)
{{-- Internal links swap the page in place (no full reload); external links, new tabs and downloads opt out. --}}
has('target') && str_starts_with($href, url('/'))) wire:navigate.hover @endif {{ $attributes->merge(['class' => $class]) }}>{{ $slot }}
@else
@endif