@extends('layouts.master')

@section('title', 'Tariffs - Prolex Law Firm')

@section('content')
<style>
    .container {
        max-width: 1200px;
        margin: 40px auto;
        background-color: #f8fafc;
        padding: 30px;
        border-radius: 12px;
        box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    }

    h1 {
        text-align: center;
        color: #1e40af;
        margin-bottom: 30px;
        font-size: 2.5rem;
        font-weight: 700;
    }

    .actions {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20px;
    }

    .add-btn {
        background: linear-gradient(135deg, #3b82f6, #1d4ed8);
        color: white;
        padding: 12px 24px;
        border: none;
        border-radius: 8px;
        font-size: 1rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        text-decoration: none;
        display: inline-block;
    }

    .add-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(59, 130, 246, 0.4);
    }

    .search-container {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    #searchInput {
        padding: 10px 15px;
        border: 2px solid #e2e8f0;
        border-radius: 6px;
        font-size: 1rem;
        width: 300px;
    }

    #searchInput:focus {
        outline: none;
        border-color: #3b82f6;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }

    .table-container {
        background: white;
        border-radius: 8px;
        overflow: hidden;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }

    table {
        width: 100%;
        border-collapse: collapse;
    }

    th, td {
        padding: 15px;
        text-align: left;
        border-bottom: 1px solid #e2e8f0;
    }

    th {
        background-color: #f8fafc;
        font-weight: 600;
        color: #374151;
        font-size: 0.95rem;
    }

    td {
        color: #4b5563;
        font-size: 0.9rem;
    }

    tr:hover {
        background-color: #f9fafb;
    }

    .action-btn {
        padding: 6px 12px;
        border: none;
        border-radius: 4px;
        font-size: 0.85rem;
        font-weight: 500;
        cursor: pointer;
        text-decoration: none;
        display: inline-block;
        margin-right: 5px;
    }

    .view-btn {
        background-color: #10b981;
        color: white;
    }

    .edit-btn {
        background-color: #f59e0b;
        color: white;
    }

    .delete-btn {
        background-color: #ef4444;
        color: white;
    }

    .view-btn:hover {
        background-color: #059669;
    }

    .edit-btn:hover {
        background-color: #d97706;
    }

    .delete-btn:hover {
        background-color: #dc2626;
    }

    .no-tariffs {
        text-align: center;
        color: #6b7280;
        font-style: italic;
    }
</style>

<div class="container">
    <h1>Tariffs</h1>

    <div class="actions">
        <a href="{{ route('tariffs.create') }}" class="add-btn">Add Tariff</a>
        <div class="search-container">
            <input type="text" id="searchInput" placeholder="Search tariffs...">
        </div>
    </div>

    <div class="table-container">
        <table id="tariffsTable">
            <thead>
                <tr>
                    <th>Lawyer Tier</th>
                    <th>Service Name</th>
                    <th>Rate Type</th>
                    <th>Rate Amount</th>
                    <th>Description</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                @forelse($tariffs as $tariff)
                <tr>
                    <td>{{ $tariff->lawyer_tier }}</td>
                    <td>{{ $tariff->service_name }}</td>
                    <td>{{ $tariff->rate_type }}</td>
                    <td>{{ $tariff->rate_amount }}</td>
                    <td>{{ $tariff->description }}</td>
                    <td>
                        <a href="{{ route('tariffs.show', $tariff->id) }}" class="action-btn view-btn">View</a>
                        <a href="{{ route('tariffs.edit', $tariff->id) }}" class="action-btn edit-btn">Edit</a>
                        <form action="{{ route('tariffs.destroy', $tariff->id) }}" method="POST" style="display: inline;">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="action-btn delete-btn" onclick="return confirm('Are you sure you want to delete this tariff?')">Delete</button>
                        </form>
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="6" class="no-tariffs">No tariffs found.</td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>

<script>
    // Search functionality
    document.getElementById('searchInput').addEventListener('input', function() {
        const searchTerm = this.value.toLowerCase();
        const rows = document.querySelectorAll('#tariffsTable tbody tr');

        rows.forEach(row => {
            if (row.cells.length > 1) { // Skip the "no tariffs" row
                const text = row.textContent.toLowerCase();
                row.style.display = text.includes(searchTerm) ? '' : 'none';
            }
        });
    });
</script>

@endsection

