@extends('layout.admin')
@section('content')

<style>
  .wrap{max-width:720px;margin:0 auto;padding:14px}
  .card{background:#fff;border-radius:16px;border:1px solid #e2e8f0;box-shadow:0 10px 24px rgba(0,0,0,.04);overflow:hidden}
  .head{padding:14px 16px;border-bottom:1px solid #f1f5f9;font-weight:1000;color:#0f172a}
  .body{padding:14px 16px}
  .grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}
  .field{border:1px solid #e2e8f0;border-radius:12px;padding:10px 12px;width:100%}
  label{font-size:12px;font-weight:900;color:#334155}
  .btn{border:none;border-radius:12px;padding:12px 14px;font-weight:1000;cursor:pointer}
  .btnBlue{background:linear-gradient(135deg,#2563eb,#1d4ed8);color:#fff}
  .btnSoft{background:#eff6ff;border:1px solid #bfdbfe;color:#1e40af;text-decoration:none;display:inline-flex;align-items:center;justify-content:center}
  .note{font-size:12px;color:#64748b;margin-top:6px}
</style>

<div class="wrap">
  <div class="card">
    <div class="head">✏️ Edit Rank: {{ $rank->name }}</div>
    <div class="body">
      @if($errors->any())
        <div style="background:#fef2f2;border:1px solid #ef444433;color:#991b1b;border-radius:12px;padding:10px 12px;font-weight:900;margin-bottom:12px">
          <ul style="margin:0;padding-left:18px">
            @foreach($errors->all() as $e)<li>{{ $e }}</li>@endforeach
          </ul>
        </div>
      @endif

      <form method="POST" action="{{ route('admin.leadership.ranks.update',$rank->id) }}" enctype="multipart/form-data">
        @csrf
        @method('PUT')

        <div class="grid">
          <div>
            <label>Key (unique)</label>
            <input class="field" name="key" value="{{ old('key',$rank->key) }}" required>
          </div>
          <div>
            <label>Name</label>
            <input class="field" name="name" value="{{ old('name',$rank->name) }}" required>
          </div>
        </div>

        <div style="margin-top:12px">
          <label>Small Title</label>
          <input class="field" name="display_title" value="{{ old('display_title',$rank->display_title) }}" placeholder="Tagline under the name">
        </div>

        <div class="grid" style="margin-top:12px">
          <div>
            <label>Update Notice (shown on click)</label>
            <input class="field" name="notice_text" value="{{ old('notice_text',$rank->notice_text) }}">
          </div>
          <div>
            <label>Display Image</label>
            <input class="field" type="file" name="display_image" accept="image/*">
            <div class="note">Leave blank to keep current. Max 2MB.</div>
            @if($rank->display_image)
              <div style="margin-top:8px">
                <img src="{{ asset($rank->display_image) }}" alt="Current image" style="width:70px;height:70px;border-radius:12px;object-fit:cover;border:1px solid #e2e8f0">
              </div>
            @endif
          </div>
        </div>

        <div class="grid" style="margin-top:12px">
          <div>
            <label>Need Verified Members</label>
            <input class="field" type="number" min="0" name="need_verified_members" value="{{ old('need_verified_members',$rank->need_verified_members) }}" required>
          </div>
          <div>
            <label>Count 2nd Level?</label>
            <select class="field" name="include_level2_verified">
              <option value="0" @selected(old('include_level2_verified',$rank->include_level2_verified)==0)>No</option>
              <option value="1" @selected(old('include_level2_verified',$rank->include_level2_verified)==1)>Yes</option>
            </select>
          </div>
          <div>
            <label>Need 2nd Level Members</label>
            <input class="field" type="number" min="0" name="need_level2_members" value="{{ old('need_level2_members',$rank->need_level2_members) }}">
          </div>
          <div>
            <label>Count 3rd Level?</label>
            <select class="field" name="include_level3_verified">
              <option value="0" @selected(old('include_level3_verified',$rank->include_level3_verified)==0)>No</option>
              <option value="1" @selected(old('include_level3_verified',$rank->include_level3_verified)==1)>Yes</option>
            </select>
          </div>
          <div>
            <label>Need 3rd Level Members</label>
            <input class="field" type="number" min="0" name="need_level3_members" value="{{ old('need_level3_members',$rank->need_level3_members) }}">
          </div>
          <div>
            <label>Keep Count After Unverify?</label>
            <select class="field" name="keep_count_after_unverify">
              <option value="1" @selected(old('keep_count_after_unverify',$rank->keep_count_after_unverify)==1)>Yes</option>
              <option value="0" @selected(old('keep_count_after_unverify',$rank->keep_count_after_unverify)==0)>No</option>
            </select>
          </div>
          <div>
            <label>Need Gmail (completed)</label>
            <input class="field" type="number" min="0" name="need_gmail_completed" value="{{ old('need_gmail_completed',$rank->need_gmail_completed) }}" required>
          </div>
        </div>

        <div class="grid" style="margin-top:12px">
          <div>
            <label>Need Facebook (approved)</label>
            <input class="field" type="number" min="0" name="need_fb_approved" value="{{ old('need_fb_approved',$rank->need_fb_approved) }}" required>
          </div>
          <div>
            <label>Reward Amount</label>
            <input class="field" type="number" step="0.01" min="0" name="reward_amount" value="{{ old('reward_amount',$rank->reward_amount) }}" required>
          </div>
        </div>

        <div class="grid" style="margin-top:12px">
          <div>
            <label>Count Start At</label>
            <input class="field" type="datetime-local" name="count_start_at"
              value="{{ old('count_start_at', optional($rank->count_start_at)->format('Y-m-d\\TH:i')) }}">
            <div class="note">এই সময়ের পর থেকে নতুন কাউন্ট হবে। খালি রাখলে আগেরটা থাকবে।</div>
          </div>
          <div>
            <label>Sort Order</label>
            <input class="field" type="number" min="0" name="sort_order" value="{{ old('sort_order',$rank->sort_order) }}">
          </div>
          <div>
            <label>Active?</label>
            <select class="field" name="is_active">
              <option value="1" @selected(old('is_active',$rank->is_active)==1)>Yes</option>
              <option value="0" @selected(old('is_active',$rank->is_active)==0)>No</option>
            </select>
          </div>
        </div>

        <div style="display:flex;gap:10px;margin-top:14px">
          <button class="btn btnBlue" type="submit">Update</button>
          <a class="btn btnSoft" href="{{ route('admin.leadership.ranks.index') }}">Back</a>
        </div>
      </form>
    </div>
  </div>
</div>
@endsection
