@extends('layouts.app')

@section('page_title', 'Add Photo Slider')

@section('content')
<div class="card-header border-0 bg-transparent py-2">
    <h5 class="mb-0 fw-bold text-dark" style="font-size: 1.25rem;">Add Photo Slider</h5>
</div>
        <div class="row justify-content-center">
          
              
                   
                    <div class="card-body p-3">
                        <form id="addPhotoSliderForm">
                            <div class="mb-3">
                                <label for="title" class="form-label">Title</label>
                                <input type="text" class="form-control" id="title" placeholder="Enter title" required>
                            </div>
                            <div class="mb-3">
                                <label for="type" class="form-label">Type</label>
                                <select class="form-select" id="type" required>
                                    <option value="" disabled selected>Select type</option>
                                    <option value="Banner">Banner</option>
                                    <option value="Carousel">Carousel</option>
                                    <option value="Slider">Slider</option>
                                </select>
                            </div>
                            <div class="mb-3">
                                <label for="startDate" class="form-label">Start Date</label>
                                <input type="date" class="form-control" id="startDate" required>
                            </div>
                            <div class="mb-3">
                                <label for="endDate" class="form-label">End Date</label>
                                <input type="date" class="form-control" id="endDate" required>
                            </div>
                            <div class="d-flex justify-content-end mt-3">
                                <button type="button" class="btn btn-outline-secondary me-2" style="margin-right:5px">Cancel</button>
                                <button type="submit" class="btn btn-primary">Add Photo Slider</button>
                            </div>
                        </form>
                    </div>
             
          
        </div>
   

    <style>
        .card {
            border-radius: 5px;
            border: 1px solid #dee2e6;
        }
        .form-label {
            font-size: 0.95rem;
        }
        .form-control,
        .form-select {
            font-size: 0.9rem;
            width: 100%;
        }
    </style>

    <script>
        document.getElementById('addPhotoSliderForm').addEventListener('submit', function(e) {
            e.preventDefault();

            const title = document.getElementById('title').value;
            const type = document.getElementById('type').value;
            const startDate = document.getElementById('startDate').value;
            const endDate = document.getElementById('endDate').value;

            if (!title || !type || !startDate || !endDate) {
                alert('Please fill out all fields.');
                return;
            }

            // Simulate adding photo slider (frontend-only)
            const newSlider = {
                id: Date.now(),
                title: title,
                type: type,
                startDate: startDate,
                endDate: endDate
            };

            // Store in sessionStorage
            let sliders = JSON.parse(sessionStorage.getItem('sliders') || '[]');
            sliders.push(newSlider);
            sessionStorage.setItem('sliders', JSON.stringify(sliders));

            alert('Photo Slider added successfully!');
            window.location.href = '/photo-slider';
        });

        // Cancel button click handler
        document.querySelector('.btn-outline-secondary').addEventListener('click', function() {
            window.location.href = '/photo-slider';
        });
    </script>
@endsection