@extends('layouts.app')

@section('title', 'Edit Director')

@push('styles')
<style>
    /* Page header */
    .page-header {
        margin-bottom: 32px;
    }

    .page-title {
        display: flex;
        align-items: center;
        gap: 12px;
        color: #ffffff;
        font-size: 28px;
        font-weight: 600;
        margin-bottom: 8px;
    }

    .page-title svg {
        width: 32px;
        height: 32px;
    }

    .page-subtitle {
        color: rgba(255, 255, 255, 0.6);
        font-size: 15px;
    }

    /* Breadcrumb */
    .glass-breadcrumb {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-bottom: 16px;
        flex-wrap: wrap;
    }

    .glass-breadcrumb a {
        color: rgba(255, 255, 255, 0.6);
        text-decoration: none;
        font-size: 14px;
        transition: color 0.2s ease;
    }

    .glass-breadcrumb a:hover {
        color: #5eead4;
    }

    .glass-breadcrumb .separator {
        color: rgba(255, 255, 255, 0.4);
        font-size: 12px;
    }

    .glass-breadcrumb .current {
        color: rgba(255, 255, 255, 0.9);
        font-size: 14px;
    }

    /* Glass card */
    .glass-card {
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 16px;
        padding: 32px;
    }

    .card-title {
        display: flex;
        align-items: center;
        gap: 10px;
        color: #ffffff;
        font-size: 18px;
        font-weight: 600;
        margin: 0 0 24px 0;
        padding-bottom: 16px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .card-title svg {
        width: 22px;
        height: 22px;
    }

    /* Section titles */
    .section-title {
        display: flex;
        align-items: center;
        gap: 8px;
        color: #5eead4;
        font-size: 15px;
        font-weight: 600;
        margin: 24px 0 16px 0;
        padding-top: 16px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .section-title:first-of-type {
        margin-top: 0;
        padding-top: 0;
        border-top: none;
    }

    .section-title svg {
        width: 18px;
        height: 18px;
    }

    /* Form styles */
    .form-row {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 24px;
        margin-bottom: 0;
    }

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

    .form-group.full-width {
        grid-column: 1 / -1;
    }

    .form-label {
        display: block;
        color: rgba(255, 255, 255, 0.7);
        font-size: 14px;
        font-weight: 500;
        margin-bottom: 8px;
    }

    .form-label .required {
        color: #f87171;
        margin-left: 4px;
    }

    .glass-input {
        width: 100%;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 10px;
        color: #ffffff;
        padding: 14px 16px;
        font-size: 15px;
        transition: all 0.3s ease;
    }

    .glass-input::placeholder {
        color: rgba(255, 255, 255, 0.4);
    }

    .glass-input:focus {
        outline: none;
        border-color: #14b8a6;
        background: rgba(255, 255, 255, 0.15);
        box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.2);
    }

    .glass-input.is-invalid {
        border-color: #f87171;
        background: rgba(239, 68, 68, 0.1);
    }

    .glass-input.is-invalid:focus {
        box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
    }

    textarea.glass-input {
        min-height: 100px;
        resize: vertical;
    }

    .invalid-feedback {
        display: block;
        color: #f87171;
        font-size: 13px;
        margin-top: 8px;
    }

    .form-hint {
        color: rgba(255, 255, 255, 0.5);
        font-size: 13px;
        margin-top: 6px;
    }

    /* Button styles */
    .form-actions {
        display: flex;
        gap: 12px;
        justify-content: flex-end;
        margin-top: 32px;
        padding-top: 24px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .btn-gradient {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        background: linear-gradient(90deg, #14b8a6, #06b6d4);
        color: #ffffff;
        text-decoration: none;
        padding: 14px 28px;
        border-radius: 10px;
        font-size: 15px;
        font-weight: 600;
        transition: all 0.3s ease;
        box-shadow: 0 4px 15px rgba(20, 184, 166, 0.3);
        border: none;
        cursor: pointer;
    }

    .btn-gradient:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(20, 184, 166, 0.4);
        color: #ffffff;
    }

    .btn-gradient svg {
        width: 18px;
        height: 18px;
    }

    .btn-ghost {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        background: transparent;
        color: rgba(255, 255, 255, 0.8);
        text-decoration: none;
        padding: 14px 28px;
        border-radius: 10px;
        font-size: 15px;
        font-weight: 500;
        border: 1px solid rgba(255, 255, 255, 0.3);
        transition: all 0.3s ease;
        cursor: pointer;
    }

    .btn-ghost:hover {
        background: rgba(255, 255, 255, 0.1);
        border-color: rgba(255, 255, 255, 0.5);
        color: #ffffff;
    }

    .btn-ghost svg {
        width: 18px;
        height: 18px;
    }

    /* Responsive */
    @media (max-width: 768px) {
        .form-row {
            grid-template-columns: 1fr;
            gap: 0;
        }

        .form-actions {
            flex-direction: column;
        }

        .btn-gradient, .btn-ghost {
            width: 100%;
            justify-content: center;
        }

        .glass-card {
            padding: 24px;
        }
    }
</style>
@endpush

@section('content')
<!-- Breadcrumb -->
<div class="glass-breadcrumb">
    <a href="{{ route('dashboard') }}">Dashboard</a>
    <span class="separator">/</span>
    <a href="{{ route('directors.index') }}">Directors</a>
    <span class="separator">/</span>
    <a href="{{ route('directors.show', $director) }}">{{ $director->english_name }}</a>
    <span class="separator">/</span>
    <span class="current">Edit</span>
</div>

<!-- Page Header -->
<div class="page-header">
    <h1 class="page-title">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
            <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
        </svg>
        Edit Director
    </h1>
    <p class="page-subtitle">Update director information and details</p>
</div>

<!-- Form Card -->
<div class="glass-card" style="max-width: 900px;">
    <h2 class="card-title">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
            <circle cx="12" cy="7" r="4"></circle>
        </svg>
        Director Details
    </h2>

    <form action="{{ route('directors.update', $director) }}" method="POST">
        @csrf
        @method('PUT')

        @if(auth()->user()->isSuperAdmin())
            <div class="form-group">
                <label for="audit_company_id" class="form-label">
                    Audit Company / 審計公司 <span class="required">*</span>
                </label>
                <select class="glass-input @error('audit_company_id') is-invalid @enderror"
                        id="audit_company_id"
                        name="audit_company_id"
                        style="max-width: 400px;"
                        required>
                    <option value="">Select an audit company</option>
                    @foreach($auditCompanies as $auditCompany)
                        <option value="{{ $auditCompany->id }}" {{ old('audit_company_id', $director->audit_company_id) == $auditCompany->id ? 'selected' : '' }}>
                            {{ $auditCompany->name }}
                        </option>
                    @endforeach
                </select>
                @error('audit_company_id')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>
        @endif

        <!-- Name Information Section -->
        <div class="section-title">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
                <circle cx="12" cy="7" r="4"></circle>
            </svg>
            Name Information / 名稱資料
        </div>

        <div class="form-row">
            <div class="form-group">
                <label for="english_name" class="form-label">
                    English Name / 英文名 <span class="required">*</span>
                </label>
                <input type="text"
                       class="glass-input @error('english_name') is-invalid @enderror"
                       id="english_name"
                       name="english_name"
                       value="{{ old('english_name', $director->english_name) }}"
                       placeholder="Enter English name"
                       required>
                @error('english_name')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>

            <div class="form-group">
                <label for="chinese_name" class="form-label">
                    Chinese Name / 中文名
                </label>
                <input type="text"
                       class="glass-input @error('chinese_name') is-invalid @enderror"
                       id="chinese_name"
                       name="chinese_name"
                       value="{{ old('chinese_name', $director->chinese_name) }}"
                       placeholder="輸入中文名">
                @error('chinese_name')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>

            <div class="form-group">
                <label for="alias" class="form-label">
                    Alias / 別名
                </label>
                <input type="text"
                       class="glass-input @error('alias') is-invalid @enderror"
                       id="alias"
                       name="alias"
                       value="{{ old('alias', $director->alias) }}"
                       placeholder="Enter alias (if any)">
                @error('alias')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>

            <div class="form-group">
                <label for="previous_name" class="form-label">
                    Previous Name / 前用名
                </label>
                <input type="text"
                       class="glass-input @error('previous_name') is-invalid @enderror"
                       id="previous_name"
                       name="previous_name"
                       value="{{ old('previous_name', $director->previous_name) }}"
                       placeholder="Enter previous name (if any)">
                @error('previous_name')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>
        </div>

        <!-- Identification Section -->
        <div class="section-title">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <rect x="2" y="5" width="20" height="14" rx="2"></rect>
                <line x1="2" y1="10" x2="22" y2="10"></line>
            </svg>
            Identification / 身份證明
        </div>

        <div class="form-row">
            <div class="form-group">
                <label for="hkid_or_ci_number" class="form-label">
                    HKID No. / CI No. / 身份證/註冊証號碼
                </label>
                <input type="text"
                       class="glass-input @error('hkid_or_ci_number') is-invalid @enderror"
                       id="hkid_or_ci_number"
                       name="hkid_or_ci_number"
                       value="{{ old('hkid_or_ci_number', $director->hkid_or_ci_number) }}"
                       placeholder="e.g., A123456(7)">
                @error('hkid_or_ci_number')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
                <p class="form-hint">Hong Kong ID or Company CI Number</p>
            </div>

            <div class="form-group">
                <label for="passport_number" class="form-label">
                    Passport No. / 護照號碼
                </label>
                <input type="text"
                       class="glass-input @error('passport_number') is-invalid @enderror"
                       id="passport_number"
                       name="passport_number"
                       value="{{ old('passport_number', $director->passport_number) }}"
                       placeholder="Enter passport number">
                @error('passport_number')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>

            <div class="form-group">
                <label for="passport_issuing_country" class="form-label">
                    Passport Issuing Country / 譋照發行國
                </label>
                <input type="text"
                       class="glass-input @error('passport_issuing_country') is-invalid @enderror"
                       id="passport_issuing_country"
                       name="passport_issuing_country"
                       value="{{ old('passport_issuing_country', $director->passport_issuing_country) }}"
                       placeholder="e.g., China, USA, UK">
                @error('passport_issuing_country')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>
        </div>

        <!-- Address & Other Information Section -->
        <div class="section-title">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"></path>
                <circle cx="12" cy="10" r="3"></circle>
            </svg>
            Address & Other Information / 地址及其他資料
        </div>

        <div class="form-row">
            <div class="form-group">
                <label for="residential_address" class="form-label">
                    Residential Address / 通常住址
                </label>
                <textarea class="glass-input @error('residential_address') is-invalid @enderror"
                          id="residential_address"
                          name="residential_address"
                          placeholder="Enter residential address"
                          rows="3">{{ old('residential_address', $director->residential_address) }}</textarea>
                @error('residential_address')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>

            <div class="form-group">
                <label for="other_directorships" class="form-label">
                    Other Directorships / 其他董事職務
                </label>
                <textarea class="glass-input @error('other_directorships') is-invalid @enderror"
                          id="other_directorships"
                          name="other_directorships"
                          placeholder="List other directorships held"
                          rows="3">{{ old('other_directorships', $director->other_directorships) }}</textarea>
                @error('other_directorships')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>
        </div>

        <div class="form-row">
            <div class="form-group full-width">
                <label for="remarks" class="form-label">
                    Remarks / 備註
                </label>
                <textarea class="glass-input @error('remarks') is-invalid @enderror"
                          id="remarks"
                          name="remarks"
                          placeholder="Any additional notes"
                          rows="2">{{ old('remarks', $director->remarks) }}</textarea>
                @error('remarks')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>
        </div>

        <div class="form-actions">
            <a href="{{ route('directors.show', $director) }}" class="btn-ghost">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                    <line x1="18" y1="6" x2="6" y2="18"></line>
                    <line x1="6" y1="6" x2="18" y2="18"></line>
                </svg>
                Cancel
            </a>
            <button type="submit" class="btn-gradient">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                    <polyline points="20 6 9 17 4 12"></polyline>
                </svg>
                Update Director
            </button>
        </div>
    </form>
</div>
@endsection
