@extends('admin.layouts.app')

@section('title', 'Edit Menu')

@section('content')
<div class="action-bar">
    <h2 style="color:#fff;font-size:1.3rem;font-weight:700">Edit Menu: {{ $menu->name }}</h2>
    <a href="{{ route('admin.menus.index') }}" class="btn btn-dark btn-sm">&larr; Back</a>
</div>

<div class="card" style="max-width:700px">
    <form method="POST" action="{{ route('admin.menus.update', $menu) }}">
        @csrf @method('PUT')

        <div class="form-row">
            <div class="form-group">
                <label>Name *</label>
                <input type="text" name="name" class="form-control" value="{{ old('name', $menu->name) }}" required>
                @error('name') <small style="color:#e74c3c">{{ $message }}</small> @enderror
            </div>
            <div class="form-group">
                <label>Icon (emoji)</label>
                <input type="text" name="icon" class="form-control" value="{{ old('icon', $menu->icon) }}" placeholder="e.g. &#9733;">
                @error('icon') <small style="color:#e74c3c">{{ $message }}</small> @enderror
            </div>
        </div>

        <div class="form-group">
            <label>URL</label>
            <input type="text" name="url" class="form-control" value="{{ old('url', $menu->url) }}" placeholder="https://example.com or /page/slug">
            @error('url') <small style="color:#e74c3c">{{ $message }}</small> @enderror
        </div>

        <div class="form-group">
            <label>Route Name</label>
            <select name="route_name" class="form-control">
                <option value="">— None —</option>
                @foreach($routes as $name => $info)
                    <option value="{{ $name }}" {{ old('route_name', $menu->route_name) == $name ? 'selected' : '' }}>{{ $name }}</option>
                @endforeach
            </select>
            @error('route_name') <small style="color:#e74c3c">{{ $message }}</small> @enderror
        </div>

        <div class="form-row">
            <div class="form-group">
                <label>Parent Menu</label>
                <select name="parent_id" class="form-control">
                    <option value="">— Top Level —</option>
                    @foreach($parentMenus as $parent)
                        <option value="{{ $parent->id }}" {{ old('parent_id', $menu->parent_id) == $parent->id ? 'selected' : '' }}>{{ $parent->name }}</option>
                    @endforeach
                </select>
                @error('parent_id') <small style="color:#e74c3c">{{ $message }}</small> @enderror
            </div>
            <div class="form-group">
                <label>Location</label>
                <select name="location" class="form-control">
                    <option value="header" {{ old('location', $menu->location) == 'header' ? 'selected' : '' }}>Header</option>
                    <option value="footer" {{ old('location', $menu->location) == 'footer' ? 'selected' : '' }}>Footer</option>
                    <option value="both" {{ old('location', $menu->location) == 'both' ? 'selected' : '' }}>Both</option>
                </select>
                @error('location') <small style="color:#e74c3c">{{ $message }}</small> @enderror
            </div>
        </div>

        <div class="form-row">
            <div class="form-group">
                <label>Target</label>
                <select name="target" class="form-control">
                    <option value="_self" {{ old('target', $menu->target) == '_self' ? 'selected' : '' }}>Same tab</option>
                    <option value="_blank" {{ old('target', $menu->target) == '_blank' ? 'selected' : '' }}>New tab</option>
                </select>
            </div>
            <div class="form-group">
                <label>Order</label>
                <input type="number" name="order" class="form-control" value="{{ old('order', $menu->order) }}" min="0">
            </div>
        </div>

        <div class="form-group">
            <label class="checkbox-label">
                <input type="checkbox" name="is_active" value="1" {{ old('is_active', $menu->is_active) ? 'checked' : '' }}>
                Active
            </label>
        </div>

        <button type="submit" class="btn btn-primary">Update Menu</button>
    </form>
</div>
@endsection
