@extends('admin.layouts.app')
@section('title', isset($zone) ? 'Edit Zone Rule' : 'Add Zone Rule')
@section('breadcrumb')
    <a href="{{ route('admin.zones.index') }}">Zoning Rules</a>
    <span class="separator">/</span>
    <span class="current">{{ isset($zone) ? 'Edit' : 'Add' }}</span>
@endsection
@section('content')
<div class="page-header">
    <h1 class="page-title">
        <span class="title-icon"><i data-lucide="layers" style="width:20px;height:20px;"></i></span>
        {{ isset($zone) ? 'Edit Zone Rule' : 'Add Zone Rule' }}
    </h1>
    <p class="page-subtitle">Configure FAR, FSI, setbacks and height limits for a land use zone</p>
</div>
<div style="max-width:720px;">
    <div class="glass-card" style="padding:24px;">
        @if($errors->any())
            <div class="alert alert-error">
                <i data-lucide="alert-circle" class="alert-icon" style="width:15px;height:15px;"></i>
                <div>@foreach($errors->all() as $err)<div>{{ $err }}</div>@endforeach</div>
            </div>
        @endif
        <form method="POST" action="{{ isset($zone) ? route('admin.zones.update', $zone) : route('admin.zones.store') }}">
            @csrf
            @if(isset($zone)) @method('PUT') @endif
            <div style="display:grid;grid-template-columns:1fr 1fr;gap:16px;">
                <div class="form-group">
                    <label class="form-label">Zone Name</label>
                    <input type="text" name="name" value="{{ old('name', $zone->name ?? '') }}"
                           class="form-control" placeholder="e.g., R1 Residential" required>
                </div>
                <div class="form-group">
                    <label class="form-label">State</label>
                    <select name="state_id" class="form-control" required>
                        <option value="">Select State</option>
                        @foreach($states as $state)
                            <option value="{{ $state->id }}"
                                {{ old('state_id', $zone->state_id ?? '') == $state->id ? 'selected' : '' }}>
                                {{ $state->name }}
                            </option>
                        @endforeach
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">Zone Type</label>
                    <select name="zone_type" class="form-control" required>
                        @foreach(['Residential','Commercial','Industrial','Mixed','Agricultural','Green Belt','Heritage'] as $type)
                            <option value="{{ $type }}"
                                {{ old('zone_type', $zone->zone_type ?? '') == $type ? 'selected' : '' }}>
                                {{ $type }}
                            </option>
                        @endforeach
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">FAR / FSI</label>
                    <input type="number" name="far_fsi" value="{{ old('far_fsi', $zone->far_fsi ?? '') }}"
                           class="form-control" placeholder="e.g., 1.5" step="0.01" min="0" max="10">
                </div>
                <div class="form-group">
                    <label class="form-label">Max Height (metres)</label>
                    <input type="number" name="max_height_m" value="{{ old('max_height_m', $zone->max_height_m ?? '') }}"
                           class="form-control" placeholder="e.g., 15" min="0">
                </div>
                <div class="form-group">
                    <label class="form-label">Max Ground Coverage (%)</label>
                    <input type="number" name="max_ground_coverage" value="{{ old('max_ground_coverage', $zone->max_ground_coverage ?? '') }}"
                           class="form-control" placeholder="e.g., 40" min="0" max="100">
                </div>
                <div class="form-group">
                    <label class="form-label">Front Setback (m)</label>
                    <input type="number" name="front_setback_m" value="{{ old('front_setback_m', $zone->front_setback_m ?? '') }}"
                           class="form-control" placeholder="e.g., 4.5" step="0.1" min="0">
                </div>
                <div class="form-group">
                    <label class="form-label">Side Setback (m)</label>
                    <input type="number" name="side_setback_m" value="{{ old('side_setback_m', $zone->side_setback_m ?? '') }}"
                           class="form-control" placeholder="e.g., 2.0" step="0.1" min="0">
                </div>
                <div class="form-group">
                    <label class="form-label">Rear Setback (m)</label>
                    <input type="number" name="rear_setback_m" value="{{ old('rear_setback_m', $zone->rear_setback_m ?? '') }}"
                           class="form-control" placeholder="e.g., 3.0" step="0.1" min="0">
                </div>
                <div class="form-group">
                    <label class="form-label">Open Space Required (%)</label>
                    <input type="number" name="open_space_pct" value="{{ old('open_space_pct', $zone->open_space_pct ?? '') }}"
                           class="form-control" placeholder="e.g., 10" min="0" max="100">
                </div>
                <div class="form-group" style="grid-column:1/-1;">
                    <label class="form-label">Permitted Uses</label>
                    <textarea name="permitted_uses" rows="2" class="form-control"
                              placeholder="Comma-separated list of permitted land uses...">{{ old('permitted_uses', $zone->permitted_uses ?? '') }}</textarea>
                </div>
                <div class="form-group" style="grid-column:1/-1;">
                    <label class="form-label">Notes / Remarks</label>
                    <textarea name="notes" rows="2" class="form-control"
                              placeholder="Additional regulatory notes...">{{ old('notes', $zone->notes ?? '') }}</textarea>
                </div>
                <div class="form-group" style="grid-column:1/-1;">
                    <label style="display:flex;align-items:center;gap:8px;cursor:pointer;font-size:13px;color:var(--vsc-text-primary);">
                        <input type="checkbox" name="is_active" value="1"
                               {{ old('is_active', $zone->is_active ?? 1) ? 'checked' : '' }}
                               style="accent-color:var(--vsc-blue);">
                        Zone rule is Active
                    </label>
                </div>
            </div>
            <div class="divider"></div>
            <div style="display:flex;gap:10px;justify-content:flex-end;">
                <a href="{{ route('admin.zones.index') }}" class="btn btn-secondary">
                    <i data-lucide="x" style="width:13px;height:13px;"></i> Cancel
                </a>
                <button type="submit" class="btn btn-primary">
                    <i data-lucide="save" style="width:13px;height:13px;"></i>
                    {{ isset($zone) ? 'Save Changes' : 'Add Zone Rule' }}
                </button>
            </div>
        </form>
    </div>
</div>
@endsection
