@extends('backend.admin.layouts.app')
@section('content')
    <div class="pagetitle">
        <h1>Dashboard</h1>
        <nav>
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="index.html">Home</a></li>
                <li class="breadcrumb-item">Dashboard</li>
                <li class="breadcrumb-item active">{{ $PageTitle }}</li>
            </ol>
        </nav>
    </div>

    <section class="section dashboard">
        <div class="row">
            <div class="col-lg-10">
                <div class="card">
                    <div class="card-body mt-3">
                        <form action="{{ route('admin.slider.update', $slider->id) }}" method="POST" enctype="multipart/form-data">
                            @csrf
                            @method('PUT')

                            <div class="row mb-3 mt-4">
                                <label for="title" class="col-sm-3 col-form-label">Right Side Title</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control @error('title') is-invalid @enderror" id="title" name="title" value="{{ old('title', $slider->title) }}" placeholder="Enter headline text" required>
                                    @error('title') <div class="invalid-feedback">{{ $message }}</div> @enderror
                                </div>
                            </div>

                            <div class="row mb-3">
                                <label for="description" class="col-sm-3 col-form-label">Right Side Description</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control @error('description') is-invalid @enderror" id="description" name="description" rows="5" placeholder="Enter header text" required>{{ old('description', $slider->description) }}</textarea>
                                    @error('description') <div class="invalid-feedback">{{ $message }}</div> @enderror
                                </div>
                            </div>

                            <div class="row mb-3">
                                <label for="youtube_url" class="col-sm-3 col-form-label">Left Side YouTube Video</label>
                                <div class="col-sm-9">
                                    <input type="url" class="form-control @error('youtube_url') is-invalid @enderror" id="youtube_url" name="youtube_url" value="{{ old('youtube_url', $slider->youtube_url) }}" placeholder="https://www.youtube.com/watch?v=..." required>
                                    <small class="text-muted">YouTube link update করলেই homepage header video বদলে যাবে।</small>
                                    @error('youtube_url') <div class="invalid-feedback">{{ $message }}</div> @enderror
                                </div>
                            </div>

                            <div class="row mb-3">
                                <label for="image_type" class="col-sm-3 col-form-label">Type</label>
                                <div class="col-sm-9">
                                    <select class="form-select @error('type') is-invalid @enderror" id="image_type" name="type" required>
                                        <option value="">Select type</option>
                                        <option value="large" {{ old('type', $slider->type) === 'large' ? 'selected' : '' }}>Large</option>
                                        <option value="small" {{ old('type', $slider->type) === 'small' ? 'selected' : '' }}>Small</option>
                                    </select>
                                    @error('type') <div class="invalid-feedback">{{ $message }}</div> @enderror
                                </div>
                            </div>

                            <div class="row mb-3">
                                <label for="img_ifo" class="col-sm-3 col-form-label">Alternative Info</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control @error('img_info') is-invalid @enderror" value="{{ old('img_info', $slider->alt) }}" name="img_info" id="img_ifo" placeholder="Optional alt / note">
                                    @error('img_info') <div class="invalid-feedback">{{ $message }}</div> @enderror
                                </div>
                            </div>

                            <div class="row mt-4 mb-4">
                                <label for="image" class="col-sm-3 col-form-label">Optional Poster Image</label>
                                <div class="col-sm-8 mb-25">
                                    <div class="upload-img-box">
                                        @if($slider->image)
                                            <img src="{{ asset('storage/' . $slider->image) }}" alt="{{ $slider->alt ?? 'Header image' }}">
                                        @else
                                            <img src="" alt="">
                                        @endif
                                        <input type="file" name="image" id="image" accept="image/*" onchange="previewFile(this)">
                                        <div class="upload-img-box-icon">
                                            <i class="fa-solid fa-camera"></i>
                                        </div>
                                    </div>
                                    <p class="col-sm-10 mt-2 mb-0">Optional. এটা future fallback হিসেবে রাখা আছে.</p>
                                </div>
                            </div>

                            <div class="row mb-3">
                                <div class="col-sm-10">
                                    <button type="submit" class="btn btn-primary">Save</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection

@push('style')
    <style>
        .upload-img-box {
            width: 100%;
            height: 250px;
        }
    </style>
@endpush
