@extends('admin.layout')
@section('title', isset($zone->id) ? "Edit Zone" : 'New Shipping Zone')
@section('page-title', isset($zone->id) ? 'EDIT SHIPPING ZONE' : 'NEW SHIPPING ZONE')

@section('content')
<form method="POST" action="{{ isset($zone->id) ? route('admin.shipping.update', $zone) : route('admin.shipping.store') }}">
  @csrf
  @if(isset($zone->id)) @method('PUT') @endif

  <div style="display:grid;grid-template-columns:1fr 280px;gap:20px">
    <div class="card">
      <div class="card-title" style="margin-bottom:20px">ZONE DETAILS</div>

      <div class="form-group">
        <label class="form-label">Zone Name*</label>
        <input type="text" name="name" class="form-input" value="{{ old('name', $zone->name ?? '') }}" required placeholder="e.g. Delhi NCR, Metro Cities"/>
      </div>

      <div class="form-grid">
        <div class="form-group">
          <label class="form-label">Shipping Charge (₹)*</label>
          <input type="number" name="charge" class="form-input" value="{{ old('charge', $zone->charge ?? 60) }}" required min="0" step="0.01" placeholder="60"/>
          <div class="form-hint">Set 0 for free shipping.</div>
        </div>
        <div class="form-group">
          <label class="form-label">Free Shipping Above (₹)*</label>
          <input type="number" name="free_above" class="form-input" value="{{ old('free_above', $zone->free_above ?? 499) }}" required min="0" step="0.01" placeholder="499"/>
          <div class="form-hint">Order value above which shipping is free.</div>
        </div>
      </div>

      <div class="form-group">
        <label class="form-label">Estimated Delivery (days)*</label>
        <input type="number" name="estimated_days" class="form-input" value="{{ old('estimated_days', $zone->estimated_days ?? 5) }}" required min="1" max="30" placeholder="5"/>
      </div>

      <div class="form-group">
        <label class="form-label">Pincodes <span class="form-hint">(comma or newline separated)</span></label>
        <textarea name="pincodes" class="form-input" rows="5" placeholder="110001, 110002&#10;400001&#10;600001">{{ old('pincodes', $zone->pincodes ? implode(', ', $zone->pincodes) : '') }}</textarea>
        <div class="form-hint">Leave blank to match all pincodes (catch-all zone).</div>
      </div>

      <label class="form-check">
        <input type="checkbox" name="active" value="1" {{ old('active', $zone->active ?? true) ? 'checked' : '' }}/>
        <span>Zone is Active</span>
      </label>
    </div>

    <div class="card" style="position:sticky;top:80px;height:fit-content">
      <div class="card-title" style="margin-bottom:16px">SAVE</div>
      <button type="submit" class="btn btn-primary" style="width:100%;justify-content:center;padding:13px;margin-bottom:10px">
        {{ isset($zone->id) ? '💾 Save Changes' : '🚚 Create Zone' }}
      </button>
      <a href="{{ route('admin.shipping') }}" class="btn btn-ghost" style="width:100%;justify-content:center">Cancel</a>
    </div>
  </div>
</form>
@endsection
