@extends('admin.layout')

@section('title', 'Homepage Layout Yönetimi')

@section('content')
<div class="admin-container">
    <div class="admin-header">
        <div>
            <h1>🎨 Homepage Layout Yönetimi</h1>
            <p>Platformunuzun ana sayfası için farklı layout stillerini seçin ve özelleştirin</p>
        </div>
    </div>

    @if(session('success'))
    <div class="alert alert-success alert-dismissible fade show" role="alert">
        <svg class="alert-icon" fill="currentColor" viewBox="0 0 20 20">
            <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
        </svg>
        {{ session('success') }}
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Kapat"></button>
    </div>
    @endif

    <div class="layouts-grid">
        @foreach($layouts as $layout)
        <div class="layout-card" data-layout-id="{{ $layout->id }}">
            <div class="layout-header">
                <h3>{{ $layout->label }}</h3>
                @if($layout->is_active)
                    <span class="badge badge-success">✓ Aktif</span>
                @else
                    <span class="badge badge-secondary">Pasif</span>
                @endif
            </div>

            <div class="layout-preview">
                <div class="preview-content">
                    @if($layout->name === 'classic')
                        <div style="text-align: center; padding: 24px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 8px 8px 0 0; margin-bottom: 12px;">
                            <div style="font-size: 28px; font-weight: bold; margin-bottom: 8px;">Klasik Hero</div>
                            <div style="font-size: 13px; opacity: 0.9;">Ortalanmış, 4 sütun grid</div>
                        </div>
                        <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 12px;">
                            @for($i = 0; $i < 4; $i++)
                                <div style="background: #f3f4f6; height: 40px; border-radius: 4px;"></div>
                            @endfor
                        </div>
                    @elseif($layout->name === 'split')
                        <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px; background: #f9fafb; border-radius: 8px; min-height: 80px;">
                            <div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 4px;"></div>
                            <div style="display: grid; grid-template-columns: 1fr; gap: 4px;">
                                <div style="background: #e5e7eb; height: 20px; border-radius: 4px;"></div>
                                <div style="background: #e5e7eb; height: 20px; border-radius: 4px;"></div>
                                <div style="background: #e5e7eb; height: 20px; border-radius: 4px;"></div>
                            </div>
                        </div>
                    @elseif($layout->name === 'magazine')
                        <div style="padding: 12px;">
                            <div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); height: 60px; border-radius: 4px; margin-bottom: 8px;"></div>
                            <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;">
                                @for($i = 0; $i < 3; $i++)
                                    <div style="background: #f3f4f6; height: 40px; border-radius: 4px;"></div>
                                @endfor
                            </div>
                        </div>
                    @elseif($layout->name === 'minimal')
                        <div style="padding: 20px; text-align: center; background: #f9fafb; border-radius: 8px;">
                            <div style="font-size: 18px; font-weight: bold; margin-bottom: 12px; color: #111827;">Minimal</div>
                            <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px;">
                                <div style="background: #e5e7eb; height: 30px; border-radius: 4px;"></div>
                                <div style="background: #e5e7eb; height: 30px; border-radius: 4px;"></div>
                            </div>
                        </div>
                    @elseif($layout->name === 'hero_focus')
                        <div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 24px; border-radius: 8px; color: white; text-align: center;">
                            <div style="font-size: 20px; font-weight: bold; margin-bottom: 8px;">Hero Odaklı</div>
                            <div style="font-size: 12px; opacity: 0.9; margin-bottom: 12px;">Tam ekran hero + özellikler</div>
                            <div style="display: flex; gap: 8px; justify-content: center;">
                                <div style="background: rgba(255,255,255,0.3); padding: 6px 16px; border-radius: 4px; font-size: 12px;">Buton 1</div>
                                <div style="background: rgba(255,255,255,0.2); padding: 6px 16px; border-radius: 4px; font-size: 12px; border: 1px solid rgba(255,255,255,0.3);">Buton 2</div>
                            </div>
                        </div>
                    @endif
                </div>
            </div>

            <p class="layout-description">{{ $layout->description }}</p>

            <div class="layout-settings">
                <div class="setting-row">
                    <span class="setting-label">Hero:</span>
                    <span class="setting-value">{{ ucfirst(str_replace('-', ' ', $layout->hero_layout)) }}</span>
                </div>
                <div class="setting-row">
                    <span class="setting-label">İstatistik:</span>
                    <span class="setting-value">{{ $layout->show_stats_section ? '✓' : '✗' }}</span>
                </div>
                <div class="setting-row">
                    <span class="setting-label">Blog:</span>
                    <span class="setting-value">{{ $layout->blog_columns }} sütun</span>
                </div>
                <div class="setting-row">
                    <span class="setting-label">Özellikler:</span>
                    <span class="setting-value">{{ $layout->show_features_section ? '✓' : '✗' }}</span>
                </div>
            </div>

            <div class="layout-actions">
                <a href="{{ route('admin.homepage-layouts.edit', $layout->id) }}" class="btn btn-sm btn-secondary" title="Düzenle">
                    ✎ Düzenle
                </a>
                @if(!$layout->is_active)
                    <form action="{{ route('admin.homepage-layouts.activate', $layout->id) }}" method="POST" style="display: inline;">
                        @csrf
                        <button type="submit" class="btn btn-sm btn-primary" title="Aktif Et">
                            ✓ Aktif Et
                        </button>
                    </form>
                @else
                    <button type="button" class="btn btn-sm btn-primary" disabled title="Zaten aktif">
                        ✓ Aktif
                    </button>
                @endif
            </div>
        </div>
        @endforeach
    </div>
</div>

<style>
.admin-container {
    background: #f9fafb;
    padding: 24px;
    border-radius: 12px;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid #e5e7eb;
}

.admin-header h1 {
    font-size: 28px;
    font-weight: 900;
    color: #111827;
    margin-bottom: 6px;
}

.admin-header p {
    font-size: 14px;
    color: #6b7280;
}

.layouts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

.layout-card {
    background: #ffffff;
    border: 1.5px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.layout-card:hover {
    border-color: #2563eb;
    box-shadow: 0 10px 28px rgba(37, 99, 235, 0.1);
    transform: translateY(-2px);
}

.layout-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.layout-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: #111827;
    margin: 0;
}

.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-secondary {
    background: #f3f4f6;
    color: #6b7280;
}

.layout-preview {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-content {
    width: 100%;
}

.layout-description {
    font-size: 13px;
    color: #6b7280;
    line-height: 1.5;
    margin-bottom: 16px;
}

.layout-settings {
    background: #f9fafb;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
    font-size: 13px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid #e5e7eb;
}

.setting-row:last-child {
    border-bottom: none;
}

.setting-label {
    font-weight: 600;
    color: #374151;
}

.setting-value {
    color: #6b7280;
}

.layout-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
}

.btn {
    flex: 1;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-primary {
    background: #2563eb;
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
}

.btn-primary:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

.btn-secondary {
    background: #f3f4f6;
    color: #374151;
    border-color: #d1d5db;
}

.btn-secondary:hover {
    background: #e5e7eb;
}

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert-success {
    background: #d1fae5;
    border: 1px solid #a7f3d0;
    color: #065f46;
}

.alert-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.btn-close {
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.5;
    padding: 4px;
    margin-left: auto;
}

.btn-close:hover {
    opacity: 0.75;
}

@media (max-width: 768px) {
    .layouts-grid {
        grid-template-columns: 1fr;
    }

    .admin-header {
        flex-direction: column;
    }

    .layout-actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }
}
</style>
@endsection
