@extends('layouts.admin')

@section('title', 'Create Album')

@section('content')
<div class="dashboard-header" style="margin-bottom: 24px; display: flex; justify-content: space-between; align-items: center;">
    <div>
        <nav style="font-size:0.8rem; color:var(--text-muted); margin-bottom:4px;">
            <a href="{{ route('admin.albums.index') }}" style="color:var(--text-muted); text-decoration:none;">Gallery</a>
            <span style="margin:0 6px;">/</span>
            <span style="color:var(--primary); font-weight:600;">New Album</span>
        </nav>
        <h1 style="font-family:'Oswald',sans-serif; font-size:2rem; color:var(--primary); margin:0;">Create Album</h1>
    </div>
    <a href="{{ route('admin.albums.index') }}" class="btn btn-outline">
        <i class="fas fa-arrow-left"></i> Back to Albums
    </a>
</div>

<form method="POST" action="{{ route('admin.albums.store') }}" enctype="multipart/form-data">
    @csrf
    <div style="display:grid; grid-template-columns:1fr 300px; gap:24px; align-items:start;">

        <!-- Left: Main Fields -->
        <div class="admin-card" style="margin-bottom:0;">
            <div class="admin-card-header">
                <span class="admin-card-title"><i class="fas fa-info-circle" style="color:var(--primary);margin-right:8px;"></i> Album Information</span>
            </div>
            <div class="admin-card-body">
                <div class="form-group">
                    <label class="form-label">Album Name <span style="color:var(--secondary);">*</span></label>
                    <input type="text" name="name" class="form-control" value="{{ old('name') }}" required placeholder="e.g. Provincial Championship 2026">
                </div>

                <div class="form-group" style="margin-bottom:0;">
                    <label class="form-label">Description</label>
                    <textarea name="description" class="form-control" rows="6" placeholder="Brief description of this album...">{{ old('description') }}</textarea>
                </div>
            </div>
        </div>

        <!-- Right: Cover Image + Actions -->
        <div style="display:flex;flex-direction:column;gap:24px;">

            <!-- Cover Preview -->
            <div class="admin-card" style="margin-bottom:0;">
                <div class="admin-card-header">
                    <span class="admin-card-title"><i class="fas fa-image" style="color:var(--secondary);margin-right:8px;"></i> Cover Image</span>
                </div>
                <div class="admin-card-body">
                    <div id="coverDropZone"
                         style="border:2px dashed var(--border-color);border-radius:10px;padding:30px 20px;text-align:center;cursor:pointer;transition:var(--transition);background-color:var(--bg-color);"
                         onclick="document.getElementById('coverInput').click()"
                         onmouseenter="this.style.borderColor='var(--primary)';this.style.background='rgba(30,58,138,.02)'"
                         onmouseleave="this.style.borderColor='var(--border-color)';this.style.background='var(--bg-color)'">
                        <div id="coverPreviewWrap">
                            <i class="fas fa-cloud-upload-alt" style="font-size:2rem;color:var(--text-muted);opacity:0.5;margin-bottom:8px;"></i>
                            <p style="font-size:0.9rem;color:var(--text-main);margin:0;font-weight:500;">Click to upload cover</p>
                            <p style="font-size:0.75rem;color:var(--text-muted);margin-top:4px;">JPG, PNG, WEBP · Max 4MB</p>
                        </div>
                        <img id="coverPreviewImg" src="" alt="Preview" style="display:none;width:100%;height:160px;object-fit:cover;border-radius:8px;">
                    </div>
                    <input type="file" id="coverInput" name="cover_image" accept="image/*" style="display:none;" onchange="previewCover(this)">
                </div>
            </div>

            <!-- Actions -->
            <div class="admin-card" style="margin-bottom:0;">
                <div class="admin-card-body">
                    <button type="submit" class="btn btn-primary" style="width:100%; justify-content:center; padding:12px; margin-bottom:12px;">
                        <i class="fas fa-plus-circle"></i> Create Album
                    </button>
                    <a href="{{ route('admin.albums.index') }}" class="btn btn-outline" style="width:100%; justify-content:center; padding:12px;">
                        <i class="fas fa-times"></i> Cancel
                    </a>
                </div>
            </div>
        </div>
    </div>
</form>

@endsection

@section('scripts')
<script>
function previewCover(input) {
    const img = document.getElementById('coverPreviewImg');
    const wrap = document.getElementById('coverPreviewWrap');
    if (input.files && input.files[0]) {
        const reader = new FileReader();
        reader.onload = e => {
            img.src = e.target.result;
            img.style.display = 'block';
            wrap.style.display = 'none';
        };
        reader.readAsDataURL(input.files[0]);
    }
}
</script>
@endsection
