@php
    use App\Helpers\EmpresaTurismoFileHelper;

    $currentPath = $currentPath ?? null;
    $linkName = $linkName ?? ($name . 'Link');
    $currentLink = old($linkName, $currentLink ?? null);
    $downloadUrl = EmpresaTurismoFileHelper::publicUrl($currentPath);
@endphp

<div class="mb-3">
    <label for="{{ $inputId ?? $name }}" class="form-label text-bold">{{ $label }}:</label>
    <input
        type="file"
        class="form-control @error($name) is-invalid @enderror"
        name="{{ $name }}"
        id="{{ $inputId ?? $name }}"
        accept="application/pdf,image/jpeg,image/png"
    />
    @error($name)
        <small class="text-danger text-bold">{{ $message }}</small><br>
    @enderror
    @if(!empty($description))
        <small class="d-block text-secondary">{{ $description }}</small>
    @endif
    @if($downloadUrl)
        <div class="mt-2">
            <a href="{{ $downloadUrl }}" class="text-primary" target="_blank" rel="noopener noreferrer" download>
                {{ $downloadLabel ?? __('Documento anexado') }} — <small>{{ __('baixar') }}</small>
                <i class="fa-solid fa-download" aria-hidden="true"></i>
            </a>
        </div>
    @endif

    <div class="mt-3 pt-2">
        <label for="{{ $linkName }}" class="form-label text-bold mb-1">{{ __('Link externo (opcional)') }}:</label>
        <input
            type="url"
            class="form-control form-control-sm @error($linkName) is-invalid @enderror"
            name="{{ $linkName }}"
            id="{{ $linkName }}"
            value="{{ $currentLink }}"
            placeholder="{{ __('https://drive.google.com/...') }}"
            autocomplete="off"
        />
        @error($linkName)
            <small class="text-danger text-bold">{{ $message }}</small>
        @enderror
        <small class="text-secondary d-block mt-1">{{ __('Use quando o documento estiver hospedado externamente (Google Drive, etc.) em vez de upload.') }}</small>
        @if($currentLink)
            <div class="mt-2">
                <a href="{{ $currentLink }}" class="text-primary" target="_blank" rel="noopener noreferrer">
                    {{ __('Abrir link externo') }}
                    <i class="fa-solid fa-external-link-alt" aria-hidden="true"></i>
                </a>
            </div>
        @endif
    </div>
</div>
