@php /** @var \App\Models\ClientSslCertificate $sslCertificate */ @endphp
<div class="card mb-3 border-0 shadow-sm">
    <div class="card-body">
        <h5 class="mb-3">
            <i class="fas fa-shield-alt me-2 text-primary"></i>{{ __('store.ssl_certificate_title') }}
        </h5>

        <dl class="row mb-3">
            <dt class="col-sm-3">{{ __('store.ssl_common_name') }}</dt>
            <dd class="col-sm-9"><code>{{ $sslCertificate->common_name }}</code></dd>

            @if(! empty($sslCertificate->alt_names))
                <dt class="col-sm-3">{{ __('store.ssl_alt_names') }}</dt>
                <dd class="col-sm-9">
                    @foreach($sslCertificate->alt_names as $san)
                        <span class="badge bg-secondary me-1">{{ $san }}</span>
                    @endforeach
                </dd>
            @endif

            <dt class="col-sm-3">{{ __('store.ssl_status') }}</dt>
            <dd class="col-sm-9">
                @if($sslCertificate->isRevoked())
                    <span class="badge bg-danger">{{ __('store.ssl_status_revoked') }}</span>
                @elseif($sslCertificate->isExpired())
                    <span class="badge bg-secondary">{{ __('store.ssl_status_expired') }}</span>
                @elseif($sslCertificate->installed)
                    <span class="badge bg-success">{{ __('store.ssl_status_installed') }}</span>
                @else
                    <span class="badge bg-warning text-dark">{{ __('store.ssl_status_pending_install') }}</span>
                @endif
                @if($sslCertificate->issuer)
                    <small class="text-muted ms-2">{{ $sslCertificate->issuer }}</small>
                @endif
            </dd>

            @if($sslCertificate->installed_at)
                <dt class="col-sm-3">{{ __('store.ssl_installed_at') }}</dt>
                <dd class="col-sm-9">{{ $sslCertificate->installed_at->format('Y-m-d H:i') }}</dd>
            @endif

            @if($sslCertificate->expires_at)
                <dt class="col-sm-3">{{ __('store.ssl_expires_at') }}</dt>
                <dd class="col-sm-9">
                    {{ $sslCertificate->expires_at->format('Y-m-d') }}
                    @php $days = $sslCertificate->daysUntilExpiry(); @endphp
                    @if($days !== null)
                        @if($days < 0)
                            <span class="badge bg-danger ms-2">{{ __('store.ssl_expired_n_days_ago', ['days' => abs($days)]) }}</span>
                        @elseif($days <= 30)
                            <span class="badge bg-warning text-dark ms-2">{{ __('store.ssl_expires_in_n_days', ['days' => $days]) }}</span>
                        @else
                            <small class="text-muted ms-2">{{ __('store.ssl_expires_in_n_days', ['days' => $days]) }}</small>
                        @endif
                    @endif
                </dd>
            @endif
        </dl>

        @if(! $sslCertificate->installed && ! $sslCertificate->isRevoked())
            <a href="{{ route('store.auth.services.ssl.install.show', $service->id) }}" class="btn btn-primary">
                <i class="fas fa-play-circle me-1"></i>{{ __('store.ssl_start_installation') }}
            </a>
        @elseif($sslCertificate->installed && $sslCertificate->certificate)
            <div class="accordion" id="sslCertificateAccordion">
                <div class="accordion-item">
                    <h2 class="accordion-header">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sslCertPem">
                            <i class="fas fa-file-code me-2"></i>{{ __('store.ssl_show_certificate') }}
                        </button>
                    </h2>
                    <div id="sslCertPem" class="accordion-collapse collapse" data-bs-parent="#sslCertificateAccordion">
                        <div class="accordion-body">
                            <pre class="mb-0" style="white-space: pre-wrap; font-size: 11px;">{{ trim($sslCertificate->certificate) }}@if($sslCertificate->certificate_chain)

{{ trim($sslCertificate->certificate_chain) }}@endif</pre>
                        </div>
                    </div>
                </div>
            </div>

            @if($sslCertificate->private_key && ! $sslCertificate->private_key_downloaded)
                <div class="alert alert-warning mt-3 mb-0">
                    <i class="fas fa-exclamation-triangle me-2"></i>
                    <strong>{{ __('store.ssl_private_key_one_time_warning_title') }}</strong>
                    <p class="mb-2 small">{{ __('store.ssl_private_key_one_time_warning_body') }}</p>
                    <a href="{{ route('store.auth.services.ssl.key-download', $service->id) }}" class="btn btn-sm btn-warning">
                        <i class="fas fa-key me-1"></i>{{ __('store.ssl_download_private_key') }}
                    </a>
                </div>
            @elseif($sslCertificate->private_key_downloaded)
                <div class="alert alert-secondary mt-3 mb-0 small">
                    <i class="fas fa-lock me-2"></i>{{ __('store.ssl_private_key_already_downloaded_msg') }}
                </div>
            @endif
        @endif

        @if($sslCertificate->last_error)
            <div class="alert alert-danger mt-3 mb-0 small">
                <strong>{{ __('store.ssl_last_error') }}:</strong> {{ $sslCertificate->last_error }}
            </div>
        @endif
    </div>
</div>
