@extends('admin.layouts.app')

@section('title', 'Edit Admin Profile ')
@section('page-title', 'Edit Admin Profile')
@section('breadcrumb', 'Home / Edit Profile')

@section('styles')
<style>
  :root{
    --teal:#00b09b;--teal-dk:#008f7a;--teal-lt:rgba(0,176,155,.10);--teal-glow:rgba(0,176,155,.20);
    --blue:#1a8fff;--red:#e74c3c;--red-lt:rgba(231,76,60,.10);
    --text:#2c3e50;--text-mid:#546e7a;--muted:#90a4ae;
    --border:#e0e7ef;--white:#fff;--bg:#f0f3f8;--input-bg:#f8fafc;
    --sh:0 2px 10px rgba(0,0,0,.07);--sh-md:0 4px 20px rgba(0,0,0,.09);
  }

  /* ── page header ── */
  .pg-hdr{display:flex;align-items:center;justify-content:space-between;margin-bottom:22px;flex-wrap:wrap;gap:10px}
  .pg-hdr h1{font-size:20px;font-weight:900;color:var(--text)}
  .pg-hdr .sub{font-size:11.5px;color:var(--muted);margin-top:3px}
  .breadcrumb-bar{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--muted);margin-bottom:20px}
  .breadcrumb-bar a{color:var(--teal);text-decoration:none;font-weight:600}
  .breadcrumb-bar a:hover{text-decoration:underline}
  .bc-sep{font-size:10px}

  /* ── layout grid ── */
  .edit-grid{display:grid;grid-template-columns:260px 1fr;gap:20px;align-items:start}

  /* ── profile card (left) ── */
  .profile-card{
    background:var(--white);border:1px solid var(--border);
    border-radius:14px;padding:28px 22px;
    text-align:center;
    box-shadow:var(--sh);
    animation:cIn .4s ease both;
  }
  @keyframes cIn{from{opacity:0;transform:translateY(12px)}to{opacity:1;transform:translateY(0)}}
  .avatar-wrap{position:relative;display:inline-block;margin-bottom:16px}
  .avatar-circle{
    width:90px;height:90px;border-radius:50%;
    background:linear-gradient(135deg,var(--teal),var(--teal-dk));
    display:flex;align-items:center;justify-content:center;
    font-size:36px;font-weight:900;color:#fff;
    margin:0 auto;
    box-shadow:0 6px 20px rgba(0,176,155,.3);
  }
  .avatar-badge{
    position:absolute;bottom:2px;right:2px; /* Changed from left to right for English */
    width:22px;height:22px;
    background:var(--teal);border-radius:50%;
    border:3px solid var(--white);
    display:flex;align-items:center;justify-content:center;
  }
  .avatar-badge i{font-size:10px;color:#fff}
  .profile-name{font-size:16px;font-weight:800;color:var(--text);margin-bottom:4px}
  .profile-email{font-size:12px;color:var(--muted);margin-bottom:14px;word-break:break-all}
  .profile-role{
    display:inline-flex;align-items:center;gap:5px;
    background:var(--teal-lt);color:var(--teal);
    font-size:11.5px;font-weight:700;
    padding:4px 12px;border-radius:20px;
  }
  .profile-role i{font-size:13px}
  .profile-divider{height:1px;background:var(--border);margin:18px 0}
  .profile-meta{text-align:left} /* Changed from right to left */
  .pm-item{display:flex;align-items:center;justify-content:space-between;padding:7px 0;font-size:12px}
  .pm-item:not(:last-child){border-bottom:1px solid #f3f6fa}
  .pm-lbl{color:var(--muted);display:flex;align-items:center;gap:6px}
  .pm-lbl i{font-size:14px}
  .pm-val{color:var(--text-mid);font-weight:600}

  /* ── form card (right) ── */
  .form-card{
    background:var(--white);border:1px solid var(--border);
    border-radius:14px;overflow:hidden;
    box-shadow:var(--sh);
    animation:cIn .4s .1s ease both;
  }
  .fc-header{
    display:flex;align-items:center;gap:12px;
    padding:18px 22px;border-bottom:1px solid var(--border);
    background:linear-gradient(90deg,rgba(0,176,155,.04),transparent);
  }
  .fc-icon{
    width:40px;height:40px;border-radius:10px;
    background:var(--teal-lt);
    display:flex;align-items:center;justify-content:center;
    font-size:19px;color:var(--teal);flex-shrink:0;
  }
  .fc-title{font-size:15px;font-weight:800;color:var(--text)}
  .fc-sub{font-size:11.5px;color:var(--muted);margin-top:2px}
  .fc-body{padding:26px 24px}

  /* section label */
  .section-lbl{
    display:flex;align-items:center;gap:8px;
    font-size:11.5px;font-weight:700;letter-spacing:.8px;
    color:var(--muted);text-transform:uppercase;
    margin-bottom:18px;padding-bottom:10px;
    border-bottom:1px solid var(--border);
  }
  .section-lbl i{font-size:14px;color:var(--teal)}

  /* form grid */
  .form-grid{display:grid;grid-template-columns:1fr 1fr;gap:18px;margin-bottom:24px}
  .form-grid.full{grid-template-columns:1fr}

  .fg{display:flex;flex-direction:column;gap:7px}
  .flbl{font-size:12.5px;font-weight:700;color:var(--text-mid);display:flex;align-items:center;gap:5px}
  .flbl i{font-size:14px;color:var(--muted)}
  .flbl .req{color:var(--red);margin-left:2px;font-size:13px}

  .iw{position:relative}
  .iico{position:absolute;left:13px;top:50%;transform:translateY(-50%);color:var(--muted);display:flex;font-size:16px;pointer-events:none;transition:color .2s}
  .fc-input{
    width:100%;background:var(--input-bg);
    border:1.5px solid var(--border);border-radius:10px;
    padding:12px 14px 12px 42px; /* Adjusted padding for LTR */
    font-size:13.5px;color:var(--text);
    outline:none;direction:ltr; /* Changed to LTR */
    transition:border-color .2s,box-shadow .2s,background .2s;
  }
  .fc-input::placeholder{color:#b0bec5}
  .fc-input:focus{border-color:var(--teal);background:var(--white);box-shadow:0 0 0 3px var(--teal-glow)}
  .fc-input:focus~.iico{color:var(--teal)}
  .fc-input.has-error{border-color:var(--red);background:var(--red-lt)}

  /* password strength */
  .pwd-hint{font-size:11px;color:var(--muted);margin-top:4px;display:flex;align-items:center;gap:4px}
  .pwd-hint i{font-size:13px;color:var(--teal)}

  /* eye btn */
  .eye-btn{position:absolute;right:12px;top:50%;transform:translateY(-50%);background:none;border:none;color:var(--muted);cursor:pointer;padding:4px;display:flex;transition:color .2s;border-radius:6px}
  .eye-btn:hover{color:var(--teal)}

  /* actions bar */
  .actions-bar{
    display:flex;align-items:center;justify-content:space-between;
    padding:18px 24px;
    border-top:1px solid var(--border);
    background:#fafcff;
    flex-wrap:wrap;gap:10px;
  }
  .actions-left{font-size:12px;color:var(--muted);display:flex;align-items:center;gap:6px}
  .actions-left i{font-size:14px;color:var(--teal)}
  .actions-right{display:flex;gap:10px}
  .btn-cancel{
    display:inline-flex;align-items:center;gap:6px;
    padding:10px 18px;background:var(--white);color:var(--text-mid);
    border:1.5px solid var(--border);border-radius:10px;
    font-size:13px;font-weight:600;
    cursor:pointer;text-decoration:none;transition:background .16s,border-color .16s;
  }
  .btn-cancel:hover{background:var(--bg);border-color:#c8d0de}
  .btn-save{
    display:inline-flex;align-items:center;gap:7px;
    padding:10px 22px;background:var(--teal);color:#fff;
    border:none;border-radius:10px;
    font-size:13.5px;font-weight:800;
    cursor:pointer;
    box-shadow:0 4px 14px rgba(0,176,155,.28);
    transition:background .16s,transform .14s,box-shadow .16s;
    position:relative;overflow:hidden;
  }
  .btn-save::after{content:'';position:absolute;inset:0;background:linear-gradient(180deg,rgba(255,255,255,.12) 0%,transparent 55%)}
  .btn-save:hover{background:var(--teal-dk);transform:translateY(-1px);box-shadow:0 6px 20px rgba(0,176,155,.35)}
  .btn-save:active{transform:translateY(0)}

  @media(max-width:900px){.edit-grid{grid-template-columns:1fr}.form-grid{grid-template-columns:1fr}}
</style>
@endsection

@section('content')

<div class="breadcrumb-bar">
  <a href="{{ route('admin.dashboard') }}"><i class="las la-home"></i> Dashboard</a>
  <span class="bc-sep"><i class="las la-angle-right"></i></span>
  <span>Edit Admin Data</span>
</div>

<div class="pg-hdr">
  <div>
    <h1>Edit Admin Settings</h1>
    <div class="sub">{{ $admin->name }} — Update account information and security</div>
  </div>
</div>

<div class="edit-grid">

  <div class="profile-card">
    <div class="avatar-wrap">
      <div class="avatar-circle">{{ strtoupper(mb_substr($admin->name, 0, 1)) }}</div>
      <div class="avatar-badge"><i class="las la-check"></i></div>
    </div>
    <div class="profile-name">{{ $admin->name }}</div>
    <div class="profile-email">{{ $admin->email }}</div>
    <div class="profile-role"><i class="las la-shield-alt"></i> System Admin</div>

    <div class="profile-divider"></div>

    <div class="profile-meta">
      <div class="pm-item">
        <span class="pm-lbl"><i class="las la-id-badge"></i> ID</span>
        <span class="pm-val">#{{ $admin->id }}</span>
      </div>
      <div class="pm-item">
        <span class="pm-lbl"><i class="las la-calendar-plus"></i> Created At</span>
        <span class="pm-val">{{ $admin->created_at ? $admin->created_at->format('Y-m-d') : '—' }}</span>
      </div>
      <div class="pm-item">
        <span class="pm-lbl"><i class="las la-clock"></i> Last Update</span>
        <span class="pm-val">{{ $admin->updated_at ? $admin->updated_at->format('Y-m-d') : '—' }}</span>
      </div>
      <div class="pm-item">
        <span class="pm-lbl"><i class="las la-circle"></i> Status</span>
        <span class="pm-val" style="color:var(--teal)">Active ✓</span>
      </div>
    </div>
  </div>

  <div class="form-card">
    <div class="fc-header">
      <div class="fc-icon"><i class="las la-user-edit"></i></div>
      <div>
        <div class="fc-title">Account Details</div>
        <div class="fc-sub">Update your personal information and security settings</div>
      </div>
    </div>

    <div class="fc-body">
      <form method="POST" action="{{ route('admin.update', $admin->id) }}" novalidate>
        @csrf
        @method('PUT')

        <div class="section-lbl">
          <i class="las la-user"></i>
          Basic Information
        </div>

        <div class="form-grid">

          <div class="fg">
            <label class="flbl" for="name">
              <i class="las la-user"></i> Full Name <span class="req">*</span>
            </label>
            <div class="iw">
              <input
                type="text" id="name" name="name"
                class="fc-input {{ $errors->has('name') ? 'has-error' : '' }}"
                placeholder="Enter full name"
                value="{{ old('name', $admin->name) }}"
                required
              >
              <span class="iico"><i class="las la-user"></i></span>
            </div>
            @error('name')
              <span style="font-size:11.5px;color:var(--red)"><i class="las la-exclamation-circle"></i> {{ $message }}</span>
            @enderror
          </div>

          <div class="fg">
            <label class="flbl" for="email">
              <i class="las la-envelope"></i> Email Address <span class="req">*</span>
            </label>
            <div class="iw">
              <input
                type="email" id="email" name="email"
                class="fc-input {{ $errors->has('email') ? 'has-error' : '' }}"
                placeholder="example@domain.com"
                value="{{ old('email', $admin->email) }}"
                required
              >
              <span class="iico"><i class="las la-envelope"></i></span>
            </div>
            @error('email')
              <span style="font-size:11.5px;color:var(--red)"><i class="las la-exclamation-circle"></i> {{ $message }}</span>
            @enderror
          </div>

        </div>

        <div class="section-lbl" style="margin-top:8px">
          <i class="las la-lock"></i>
          Security & Password
        </div>

        <div class="form-grid">

          <div class="fg">
            <label class="flbl" for="password">
              <i class="las la-lock"></i> New Password
            </label>
            <div class="iw">
              <input
                type="password" id="password" name="password"
                class="fc-input {{ $errors->has('password') ? 'has-error' : '' }}"
                placeholder="Leave blank to keep current"
                autocomplete="new-password"
              >
              <span class="iico"><i class="las la-lock"></i></span>
              <button type="button" class="eye-btn" onclick="togglePwd('password', this)">
                <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.8" viewBox="0 0 24 24">
                  <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
                  <circle cx="12" cy="12" r="3"/>
                </svg>
              </button>
            </div>
            <div class="pwd-hint"><i class="las la-info-circle"></i> Min. 8 characters — letters and numbers</div>
            @error('password')
              <span style="font-size:11.5px;color:var(--red)"><i class="las la-exclamation-circle"></i> {{ $message }}</span>
            @enderror
          </div>

          <div class="fg">
            <label class="flbl" for="password_confirmation">
              <i class="las la-lock"></i> Confirm Password
            </label>
            <div class="iw">
              <input
                type="password" id="password_confirmation" name="password_confirmation"
                class="fc-input"
                placeholder="Re-type new password"
                autocomplete="new-password"
              >
              <span class="iico"><i class="las la-lock"></i></span>
              <button type="button" class="eye-btn" onclick="togglePwd('password_confirmation', this)">
                <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.8" viewBox="0 0 24 24">
                  <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
                  <circle cx="12" cy="12" r="3"/>
                </svg>
              </button>
            </div>
          </div>

        </div>

      </div><div class="actions-bar">
        <div class="actions-left"></div>
        <div class="actions-right">
          <a href="{{ route('admin.dashboard') }}" class="btn-cancel">
            <i class="las la-times"></i> Cancel
          </a>
          <button type="submit" class="btn-save">
            <i class="las la-save"></i> Save Changes
          </button>
        </div>
      </div>

      </form>
    </div></div>@endsection

@section('scripts')
<script>
  function togglePwd(id, btn) {
    const inp = document.getElementById(id);
    const svg = btn.querySelector('svg');
    if (inp.type === 'password') {
      inp.type = 'text';
      svg.innerHTML = '<path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"/><path d="M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"/><line x1="1" y1="1" x2="23" y2="23"/>';
    } else {
      inp.type = 'password';
      svg.innerHTML = '<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/>';
    }
  }

  const pwd  = document.getElementById('password');
  const conf = document.getElementById('password_confirmation');
  function checkMatch() {
    if (conf.value && pwd.value !== conf.value) {
      conf.classList.add('has-error');
    } else {
      conf.classList.remove('has-error');
    }
  }
  pwd.addEventListener('input', checkMatch);
  conf.addEventListener('input', checkMatch);
</script>
@endsection