@extends('admin.layouts.app')

@section('page-title', 'Mark List')

@section('content')
<div class="card shadow-sm rounded-4 border-0 animate-card">
  <div class="card-body">
    <h4 class="mb-3 fw-bold text-dark">Mark List Management</h4>

    <style>
      /* ✨ Attractive Interactive Design without color change */
      .animate-card {
        animation: fadeInUp 0.8s ease;
      }

      @keyframes fadeInUp {
        0% {
          transform: translateY(20px);
          opacity: 0;
        }
        100% {
          transform: translateY(0);
          opacity: 1;
        }
      }

      .thead-orange th {
        background-color: #fde4b3 !important;
        font-weight: 600;
        text-align: left;
        padding: 10px 14px !important;
        border-bottom: 2px solid #f3d38b;
        color: #222;
        vertical-align: middle;
        transition: all 0.3s ease-in-out;
      }

      .thead-orange th:hover {
        background-color: #ffe6a8 !important;
        transform: translateY(-2px);
      }

      .card {
        border-radius: 1rem;
        overflow: hidden;
        box-shadow: 0 6px 18px rgba(0, 0, 0, 0.1) !important;
        transition: all 0.3s ease;
      }

      .card:hover {
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15) !important;
        transform: scale(1.01);
      }

      .table {
        background: #fff;
        border-radius: 1rem;
        overflow: hidden;
        font-size: 0.95rem;
      }

      .table-hover tbody tr {
        transition: all 0.25s ease;
      }

      .table-hover tbody tr:hover {
        background-color: #fff9e6 !important;
        cursor: pointer;
        transform: scale(1.005);
      }

      .table-bordered td, .table-bordered th {
        border: 1px solid #eaeaea !important;
      }

      .table tbody td {
        padding: 12px 18px !important;
        color: #414a58;
        vertical-align: middle;
        transition: all 0.2s ease;
      }

      /* ✨ NEW BADGE STYLES - Same as Invoice System */
      .badge {
        font-size: 11px !important;
        font-weight: 600 !important;
        padding: 6px 12px 6px 8px !important;
        border-radius: 20px !important;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        background-size: cover !important;
        background-position: center !important;
        color: #fff !important;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
        border: 2px solid transparent !important;
        min-width: 40px;
        box-sizing: border-box;
        line-height: 1.2;
        gap: 6px;
      }

      /* Status icons */
      .status-icon {
        font-size: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
      }

      /* Custom status badge backgrounds with icons */
      .badge-active { 
        background: url('/images/status-bg-paid.png') !important;
      }

      .badge-inactive { 
        background: url('/images/status-bg-overdue.png') !important;
      }

      /* Fallback colors if images don't load - ALL WITH SAME SIZE */
      .badge.badge-active { 
        background: linear-gradient(135deg, #d1fae5, #a7f3d0) !important;
        color: #065f46 !important;
        border-color: #10b981 !important;
        width: 98px;
      }

      .badge.badge-inactive { 
        background: linear-gradient(135deg, #e9d5ff, #c4b5fd) !important;
        color: #6b21a8 !important;
        border-color: #8b5cf6 !important;
      }

      /* Animation effects for badges */
      .badge.badge-active {
        animation: pulseGreen 2s infinite;
      }

      .badge.badge-inactive {
        animation: pulseRed 2s infinite;
      }

      @keyframes pulseGreen {
        0% { box-shadow: 0 0 8px #6ee86e77; }
        50% { box-shadow: 0 0 14px #5dd75d88; }
        100% { box-shadow: 0 0 8px #6ee86e77; }
      }

      @keyframes pulseRed {
        0% { box-shadow: 0 0 8px #f97f7f77; }
        50% { box-shadow: 0 0 14px #ff868677; }
        100% { box-shadow: 0 0 8px #f97f7f77; }
      }

      /* ✨ ENHANCED ACTION BUTTONS - Professional & Attractive */
      .btn-action {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        border: none;
        color: white;
        padding: 10px 22px;
        font-size: 0.85rem;
        border-radius: 12px;
        font-weight: 600;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        margin: 3px;
        cursor: pointer;
        box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        text-decoration: none;
        min-width: 120px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        position: relative;
        overflow: hidden;
      }

      .btn-action::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
        transition: left 0.5s;
      }

      .btn-action:hover::before {
        left: 100%;
      }

      .btn-action:hover {
        transform: translateY(-3px);
        box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
        color: white;
        text-decoration: none;
      }

      .btn-action:active {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
      }

      /* Specific styles for Activate button */
      .btn-action-activate {
        background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
        box-shadow: 0 4px 15px rgba(79, 172, 254, 0.3);
      }

      .btn-action-activate:hover {
        box-shadow: 0 8px 25px rgba(79, 172, 254, 0.5);
      }

      /* Specific styles for Deactivate button */
      .btn-action-deactivate {
        background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
        box-shadow: 0 4px 15px rgba(250, 112, 154, 0.3);
      }

      .btn-action-deactivate:hover {
        box-shadow: 0 8px 25px rgba(250, 112, 154, 0.5);
      }

      /* Button icons */
      .btn-icon {
        font-size: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
      }

      .text-muted {
        color: #888 !important;
        font-style: italic;
      }

      .search-container {
        position: relative;
        max-width: 380px;
        margin-bottom: 28px;
      }

      .search-container input {
        width: 100%;
        padding: 10px 14px 10px 40px;
        border-radius: 99px;
        border: 1.8px solid #d8d2bb;
        font-size: 1rem;
        box-shadow: 0 2px 7px #d2cabf96 inset;
        transition: all 0.25s ease;
      }

      .search-container input:focus {
        border-color: #7d6a05;
        outline: none;
        box-shadow: 0 0 11px #b4a024dd inset;
        transform: scale(1.02);
      }

      .search-icon {
        position: absolute;
        left: 14px;
        top: 50%;
        transform: translateY(-50%);
        font-size: 21px;
        color: #a09c82;
        pointer-events: none;
      }

      /* subtle fade for search input */
      @keyframes fadeGlow {
        from { box-shadow: 0 0 0px #b4a02455 inset; }
        to { box-shadow: 0 0 10px #b4a024aa inset; }
      }
    </style>

    @if(session('success'))
      <div class="alert alert-success rounded-3 shadow-sm">{{ session('success') }}</div>
    @endif

    <div class="search-container">
      <input type="text" id="globalSearch" placeholder="Search in all fields..." />
      <span class="search-icon">🔍</span>
    </div>

    <div class="table-responsive">
      <table class="table table-bordered table-hover align-middle" id="markListTable">
        <thead class="thead-orange">
          <tr>
            <th>#</th>
            <th>Mark No/Item No</th>
            <th>Origin</th>
            <th>Destination</th>
            <th>Customer Name</th>
            <th>Customer Id</th>
            <th>Customer No</th>
            <th>Date</th>
            <th>Status</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
          @foreach($markList as $mark)
          <tr>
            <td>{{ $mark->id }}</td>
            <td>{{ $mark->mark_no }}</td>
            <td>{{ $mark->origin }}</td>
            <td>{{ $mark->destination }}</td>
            <td>{{ $mark->customer_name }}</td>
            <td>{{ $mark->customer_id }}</td>
            <td>{{ $mark->mobile_no }}</td>
            <td>{{ \Carbon\Carbon::parse($mark->date)->format('d-m-Y') }}</td>
            <td>
              @if($mark->status == 'active')
                <span class="badge badge-active">
                  <i class="bi bi-check-circle-fill status-icon"></i>
                  Active
                </span>
              @else
                <span class="badge badge-inactive">
                  <i class="bi bi-exclamation-triangle-fill status-icon"></i>
                  In-Active
                </span>
              @endif
            </td>
            <td>
              @if($mark->status == 'active')
                <a href="{{ route('admin.marklist.toggle', $mark->id) }}" class="btn-action btn-action-deactivate">
                  <i class="bi bi-power btn-icon"></i>
                  Deactivate
                </a>
              @else
                <a href="{{ route('admin.marklist.toggle', $mark->id) }}" class="btn-action btn-action-activate">
                  <i class="bi bi-play-circle btn-icon"></i>
                  Activate
                </a>
              @endif
            </td>
          </tr>
          @endforeach
        </tbody>
      </table>

      @if($markList->isEmpty())
        <div class="py-4 text-center text-muted fst-italic">No mark numbers found.</div>
      @endif
    </div>

    <script>
      document.getElementById('globalSearch').addEventListener('input', function () {
        const filter = this.value.toLowerCase();
        const rows = document.querySelectorAll('#markListTable tbody tr');

        rows.forEach(row => {
          const text = row.textContent.toLowerCase();
          row.style.display = text.includes(filter) ? '' : 'none';
        });
      });
    </script>
  </div>
</div>
@endsection