@props([
    'module',
    'filters' => [],
    'import' => null,
    'formats' => ['xlsx', 'csv', 'pdf'],
])

@php
    $registry = app(\App\Services\ImportExport\ModuleRegistry::class);
    $supportsImport = $import ?? ($registry->exists($module) && $registry->get($module)->supportsImport());
    $query = http_build_query(array_filter($filters));
    $suffix = $query ? '?'.$query : '';
@endphp

<div class="btn-group" style="display:inline-flex; gap:6px; flex-wrap:wrap;">
    @foreach ($formats as $format)
        @php
            $label = match($format) {
                'xlsx' => 'Excel',
                'csv' => 'CSV',
                'pdf' => 'PDF',
                default => strtoupper($format),
            };
        @endphp
        <a href="{{ route('data.export', ['module' => $module, 'format' => $format]).$suffix }}"
           class="btn btn-outline btn-sm">{{ $label }}</a>
    @endforeach

    @if ($supportsImport)
        <a href="{{ route('data.import.index', $module) }}" class="btn btn-outline btn-sm">Import</a>
        <a href="{{ route('data.import.template', $module) }}" class="btn btn-ghost btn-sm">Template</a>
    @endif
</div>
