@extends('backEnd.layouts.master')
@section('title', 'Edit Custom Offer')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="page-title-box">
                <div class="page-title-right">
                    <ol class="breadcrumb m-0">
                        <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">Dashboard</a></li>
                        <li class="breadcrumb-item"><a href="{{ route('custom-offers.index') }}">Custom Offers</a></li>
                        <li class="breadcrumb-item active">Edit</li>
                    </ol>
                </div>
                <h4 class="page-title">Edit Custom Offer</h4>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-10 mx-auto">
            <div class="card">
                <div class="card-body">
                        <form action="{{ route('custom-offers.update', $offer->id) }}" method="POST" enctype="multipart/form-data">
                            @csrf
                            @method('PUT')

                            <div class="mb-3">
                                <label class="form-label">Offer Name *</label>
                                <input type="text" name="name" class="form-control" value="{{ $offer->name }}" required>
                            </div>

                            <div class="mb-3">
                                <label class="form-label">Tagline (Title Above Products)</label>
                                <input type="text" name="tagline" class="form-control" value="{{ $offer->tagline }}" placeholder="e.g. WEEKDAY DEALS!!!">
                            </div>

                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Start Date</label>
                                    <input type="date" name="start_date" class="form-control" value="{{ $offer->start_date ? $offer->start_date->format('Y-m-d') : '' }}">
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">End Date</label>
                                    <input type="date" name="end_date" class="form-control" value="{{ $offer->end_date ? $offer->end_date->format('Y-m-d') : '' }}">
                                </div>
                            </div>

                            <div class="mb-3">
                                <div class="form-check form-switch">
                                    <input type="checkbox" name="show_timer" class="form-check-input" id="show_timer" value="1" {{ $offer->show_timer ? 'checked' : '' }}>
                                    <label class="form-check-label" for="show_timer">Show Countdown Timer</label>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Accent Icon Class (FontAwesome)</label>
                                    <input type="text" name="icon" class="form-control" value="{{ $offer->icon }}" placeholder="e.g. fire, bolt, tag">
                                </div>
                                <div class="col-md-3 mb-3">
                                    <label class="form-label">Accent Color</label>
                                    <input type="color" name="color" class="form-control" value="{{ $offer->color ?? '#E31019' }}">
                                </div>
                                <div class="col-md-3 mb-3">
                                    <label class="form-label">Background Color</label>
                                    <input type="color" name="bg_color" class="form-control" value="{{ $offer->bg_color ?? '#ffffff' }}">
                                </div>
                                <div class="col-md-3 mb-3">
                                    <label class="form-label">Text Color</label>
                                    <input type="color" name="text_color" class="form-control" value="{{ $offer->text_color ?? '#222222' }}">
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Icon Banner (Top Left)</label>
                                    <input type="file" name="banner" class="form-control" accept="image/*">
                                    @if($offer->banner)
                                        <div class="mt-2">
                                            <img src="{{ asset($offer->banner) }}" style="width: 50px; height: 50px; object-fit: cover; border-radius: 4px;">
                                        </div>
                                    @endif
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Side Big Banner (Side Card)</label>
                                    <input type="file" name="side_banner" class="form-control" accept="image/*">
                                    @if($offer->side_banner)
                                        <div class="mt-2">
                                            <img src="{{ asset($offer->side_banner) }}" style="width: 80px; height: 80px; object-fit: cover; border-radius: 4px;">
                                        </div>
                                    @endif
                                </div>
                            </div>

                            <div class="mb-3">
                                <label class="form-label">Background Image (Optional)</label>
                                <input type="file" name="bg_image" class="form-control" accept="image/*">
                                @if($offer->bg_image)
                                    <div class="mt-2">
                                        <img src="{{ asset($offer->bg_image) }}" style="width: 100px; height: 60px; object-fit: cover; border-radius: 4px; border: 1px solid #ddd;">
                                    </div>
                                @endif
                            </div>


                            <div class="mb-3">
                                <label class="form-label">Banner Side</label>
                                <select name="banner_side" class="form-select">
                                    <option value="right" {{ $offer->banner_side == 'right' ? 'selected' : '' }}>Right Side</option>
                                    <option value="left" {{ $offer->banner_side == 'left' ? 'selected' : '' }}>Left Side</option>
                                </select>
                            </div>

                            <div class="mb-3">
                                <label class="form-label">Sort Order</label>
                                <input type="number" name="sort_order" class="form-control" value="{{ $offer->sort_order }}">
                            </div>

                            <div class="mb-3">
                                <div class="form-check">
                                    <input type="checkbox" name="status" class="form-check-input" id="status" value="1" {{ $offer->status ? 'checked' : '' }}>
                                    <label class="form-check-label" for="status">Active</label>
                                </div>
                            </div>

                            <div class="d-flex gap-2">
                                <button type="submit" class="btn btn-primary">Update Offer</button>
                                <a href="{{ route('custom-offers.index') }}" class="btn btn-secondary">Cancel</a>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
