@extends('backend.layout')

@section('backend_content')
    <div class="container-fluid">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <div>
                <h4 class="fw-bold mb-1">Edit Food Cart</h4>
                <small class="text-muted">Update cart details and delivery destinations.</small>
            </div>
            <a href="{{ route('admin.food-carts.index') }}" class="btn btn-light">
                <i class="bx bx-arrow-back"></i> Back
            </a>
        </div>

        <div class="card border-0 shadow-sm">
            <div class="card-body">
                <form action="{{ route('admin.food-carts.update', $foodCart) }}" method="POST"
                    enctype="multipart/form-data">
                    @csrf
                    @method('PUT')

                    <div class="mb-3">
                        <label class="form-label fw-semibold">Food Cart Name <span class="text-danger">*</span></label>
                        <input type="text" name="name" class="form-control @error('name') is-invalid @enderror"
                            value="{{ old('name', $foodCart->name) }}" required>
                        @error('name')
                            <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>

                    <div class="mb-3">
                        <label class="form-label fw-semibold">Logo</label>
                        <input type="file" name="logo" class="form-control @error('logo') is-invalid @enderror"
                            accept="image/jpeg,image/png,image/jpg,image/gif,image/webp">
                        @error('logo')
                            <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                        @if ($foodCart->logo)
                            <img src="{{ asset('storage/' . $foodCart->logo) }}" alt="{{ $foodCart->name }}"
                                class="img-thumbnail mt-2" style="max-height: 90px;">
                        @endif
                    </div>

                    <div class="mb-3">
                        <label class="form-label fw-semibold">Description</label>
                        <textarea name="description" rows="4" class="form-control @error('description') is-invalid @enderror">{{ old('description', $foodCart->description) }}</textarea>
                        @error('description')
                            <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>

                    <div class="row">
                        <div class="col-md-4 mb-3">
                            <label class="form-label fw-semibold">FoodPanda Link</label>
                            <input type="url" name="delivery_links[foodpanda]"
                                class="form-control @error('delivery_links.foodpanda') is-invalid @enderror"
                                value="{{ old('delivery_links.foodpanda', data_get($foodCart->delivery_links, 'foodpanda')) }}"
                                placeholder="https://...">
                            @error('delivery_links.foodpanda')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                        <div class="col-md-4 mb-3">
                            <label class="form-label fw-semibold">Pathao Link</label>
                            <input type="url" name="delivery_links[pathao]"
                                class="form-control @error('delivery_links.pathao') is-invalid @enderror"
                                value="{{ old('delivery_links.pathao', data_get($foodCart->delivery_links, 'pathao')) }}"
                                placeholder="https://...">
                            @error('delivery_links.pathao')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                        <div class="col-md-4 mb-3">
                            <label class="form-label fw-semibold">Foodi Link</label>
                            <input type="url" name="delivery_links[foodi]"
                                class="form-control @error('delivery_links.foodi') is-invalid @enderror"
                                value="{{ old('delivery_links.foodi', data_get($foodCart->delivery_links, 'foodi')) }}"
                                placeholder="https://...">
                            @error('delivery_links.foodi')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>

                    <div class="form-check form-switch mb-4">
                        <input class="form-check-input" type="checkbox" id="isActive" name="is_active" value="1"
                            {{ old('is_active', $foodCart->is_active) ? 'checked' : '' }}>
                        <label class="form-check-label" for="isActive">Show this cart in frontend</label>
                    </div>

                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary"><i class="bx bx-save"></i> Save Changes</button>
                        <a href="{{ route('admin.food-carts.index') }}" class="btn btn-light">Cancel</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
