@extends('layouts.master')

@section('title', 'Add Case Lawyers - ')

@section('content')
<style>
:root{--sky:#0ea5e9;--sky-deep:#0369a1;--sky-ghost:rgba(14,165,233,.07);--sky-border:rgba(14,165,233,.2);--ink-mid:#3f4a5a;--white:#fff;--off:#f7fbff;--surface:#eef6fd;--border:#daeaf8;--danger:#ef4444;--danger-bg:rgba(239,68,68,.08);--danger-border:rgba(239,68,68,.2);--amber:#f59e0b;--amber-bg:rgba(245,158,11,.08);--amber-border:rgba(245,158,11,.22);--fd:'Cormorant Garamond',Georgia,serif;--fb:'DM Sans',system-ui,sans-serif;--fm:'DM Mono',monospace}
.main-content{background:var(--off);font-family:var(--fb)}
.main-content .container,.main-content .tx-page,.main-content .page-wrap,.main-content .content-wrapper,.main-content .wrap{background:var(--white);border:1px solid var(--border);border-radius:16px;box-shadow:0 8px 24px rgba(14,165,233,.1)}
.main-content h1,.main-content h2,.main-content h3{font-family:var(--fd);color:var(--sky-deep)}
.main-content .btn,.main-content .back-btn,.main-content .option-btn,.main-content .submit-btn,.main-content .refresh-btn,.main-content .action-btn,.main-content .act-btn,.main-content .link{border-radius:10px!important;font-family:var(--fb)!important;font-weight:600!important}
.main-content .btn-secondary,.main-content .back-btn,.main-content .refresh-btn,.main-content .btn-muted,.main-content .btn-ghost{background:#fff!important;color:var(--ink-mid)!important;border:1px solid var(--sky-border)!important}
.main-content .btn-primary,.main-content .option-btn,.main-content .submit-btn{background:linear-gradient(135deg,var(--sky-deep),var(--sky))!important;color:#fff!important;border:1px solid var(--sky-deep)!important}
.main-content table,.main-content .table{border-color:var(--border)!important}
.main-content thead,.main-content thead tr,.main-content th,.main-content .table thead th,.main-content .table-head-row{background:var(--surface)!important;color:var(--ink-mid)!important;border-color:var(--border)!important}
.main-content tbody tr:hover,.main-content .tx-row:hover{background:var(--sky-ghost)!important}
.main-content input,.main-content select,.main-content textarea{border:1px solid var(--border)!important;border-radius:10px!important;font-family:var(--fb)!important}
.main-content input:focus,.main-content select:focus,.main-content textarea:focus{border-color:var(--sky)!important;box-shadow:0 0 0 3px rgba(14,165,233,.12)!important}
.main-content .rate-badge,.main-content .badge,.main-content .status-badge{font-family:var(--fm)}
.main-content .actions,.main-content .cell-actions{display:flex;gap:7px;align-items:center;flex-wrap:wrap}
.main-content a[href*='/edit'],.main-content .act-edit,.main-content .btn-warning{background:var(--amber-bg)!important;color:#92400e!important;border:1px solid var(--amber-border)!important}
.main-content .act-delete,.main-content form button[type='submit'].btn-danger,.main-content form button[onclick*='delete']{background:var(--danger-bg)!important;color:#991b1b!important;border:1px solid var(--danger-border)!important}
.main-content a[href*='/show'],.main-content .act-view{background:var(--sky-ghost)!important;color:var(--sky-deep)!important;border:1px solid var(--sky-border)!important}
</style>
<style>
    .container {
        max-width: 800px;
        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;
    }

    .back-btn {
        display: inline-block;
        background-color: #6b7280;
        color: white;
        padding: 10px 20px;
        text-decoration: none;
        border-radius: 5px;
        margin-bottom: 20px;
        transition: background-color 0.3s ease;
    }

    .back-btn:hover {
        background-color: #4b5563;
    }

    .form-group {
        margin-bottom: 20px;
    }

    label {
        display: block;
        margin-bottom: 5px;
        font-weight: 600;
        color: #374151;
    }

    select, input[type="date"] {
        width: 100%;
        padding: 10px;
        border: 2px solid #e2e8f0;
        border-radius: 6px;
        font-size: 1rem;
        transition: border-color 0.3s ease;
    }

    select:focus, input[type="date"]:focus {
        outline: none;
        border-color: #3b82f6;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }

    .lawyer-entry {
        background-color: #f1f5f9;
        padding: 20px;
        border-radius: 8px;
        margin-bottom: 20px;
        border: 1px solid #e2e8f0;
    }

    .remove-lawyer {
        background-color: #ef4444;
        color: white;
        border: none;
        padding: 8px 16px;
        border-radius: 4px;
        cursor: pointer;
        font-size: 0.9rem;
        margin-top: 10px;
        transition: background-color 0.3s ease;
    }

    .remove-lawyer:hover {
        background-color: #dc2626;
    }

    .add-lawyer-btn {
        background-color: #10b981;
        color: white;
        border: none;
        padding: 12px 24px;
        border-radius: 6px;
        cursor: pointer;
        font-size: 1rem;
        font-weight: 600;
        margin-bottom: 20px;
        transition: background-color 0.3s ease;
    }

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

    .submit-btn {
        background-color: #3b82f6;
        color: white;
        border: none;
        padding: 15px 30px;
        border-radius: 8px;
        cursor: pointer;
        font-size: 1.1rem;
        font-weight: 600;
        width: 100%;
        transition: background-color 0.3s ease;
    }

    .submit-btn:hover {
        background-color: #2563eb;
    }

    .error-message {
        color: #ef4444;
        font-size: 0.9rem;
        margin-top: 5px;
    }
</style>

<div class="container">
    <a href="{{ route('modules.edit.case-lawyers-options') }}" class="back-btn">← Back to Case Lawyers Options</a>
    <h1>Add Case Lawyers</h1>

    @if($errors->any())
        <div style="background-color: #fef2f2; border: 1px solid #fecaca; color: #dc2626; padding: 15px; border-radius: 6px; margin-bottom: 20px;">
            <ul style="margin: 0; padding-left: 20px;">
                @foreach($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    <form action="{{ route('modules.edit.store-case-lawyers') }}" method="POST" id="caseLawyersForm">
        @csrf

        <div class="form-group">
            <label for="case_id">Select Case:</label>
            <select name="case_id" id="case_id" required>
                <option value="">Choose a case...</option>
                @foreach($cases as $case)
                    <option value="{{ $case->id }}">{{ $case->case_id }} - {{ $case->case_name }}</option>
                @endforeach
            </select>
        </div>

        <div id="lawyersContainer">
            <div class="lawyer-entry">
                <div class="form-group">
                    <label>Lawyer:</label>
                    <select name="lawyers[0][lawyer_id]" required>
                        <option value="">Choose a lawyer...</option>
                        @foreach($lawyers as $lawyer)
                            <option value="{{ $lawyer->lawyer_id }}">{{ $lawyer->full_name }}</option>
                        @endforeach
                    </select>
                </div>

                <div class="form-group">
                    <label>Role:</label>
                    <select name="lawyers[0][role]" required>
                        <option value="">Choose a role...</option>
                        @foreach($lawyerRoles as $role)
                            <option value="{{ $role->name }}">{{ $role->name }}</option>
                        @endforeach
                    </select>
                </div>

                <div style="display: flex; gap: 10px;">
                    <div class="form-group" style="flex: 1;">
                        <label>Start Date:</label>
                        <input type="date" name="lawyers[0][start_date]">
                    </div>

                    <div class="form-group" style="flex: 1;">
                        <label>End Date:</label>
                        <input type="date" name="lawyers[0][end_date]">
                    </div>
                </div>
            </div>
        </div>

        <button type="button" class="add-lawyer-btn" onclick="addLawyer()">Add Another Lawyer</button>

        <button type="submit" class="submit-btn">Save Case Lawyers</button>
    </form>
</div>

<script>
    let lawyerIndex = 1;

    function addLawyer() {
        const container = document.getElementById('lawyersContainer');
        const lawyerEntry = document.createElement('div');
        lawyerEntry.className = 'lawyer-entry';
        lawyerEntry.innerHTML = `
            <div class="form-group">
                <label>Lawyer:</label>
                <select name="lawyers[${lawyerIndex}][lawyer_id]" required>
                    <option value="">Choose a lawyer...</option>
                    @foreach($lawyers as $lawyer)
                        <option value="{{ $lawyer->lawyer_id }}">{{ $lawyer->full_name }}</option>
                    @endforeach
                </select>
            </div>

            <div class="form-group">
                <label>Role:</label>
                <select name="lawyers[${lawyerIndex}][role]" required>
                    <option value="">Choose a role...</option>
                    @foreach($lawyerRoles as $role)
                        <option value="{{ $role->name }}">{{ $role->name }}</option>
                    @endforeach
                </select>
            </div>

            <div style="display: flex; gap: 10px;">
                <div class="form-group" style="flex: 1;">
                    <label>Start Date:</label>
                    <input type="date" name="lawyers[${lawyerIndex}][start_date]">
                </div>

                <div class="form-group" style="flex: 1;">
                    <label>End Date:</label>
                    <input type="date" name="lawyers[${lawyerIndex}][end_date]">
                </div>
            </div>

            <button type="button" class="remove-lawyer" onclick="removeLawyer(this)">Remove Lawyer</button>
        `;
        container.appendChild(lawyerEntry);
        lawyerIndex++;
    }

    function removeLawyer(button) {
        button.closest('.lawyer-entry').remove();
    }
</script>
@endsection


