@extends('layouts.app')

@section('title', 'Director Appointments - ' . $company->company_name)

@section('content')
<div class="row mb-4">
    <div class="col">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
                <li class="breadcrumb-item"><a href="{{ route('companies.index') }}">Companies</a></li>
                <li class="breadcrumb-item"><a href="{{ route('companies.show', $company) }}">{{ $company->company_name }}</a></li>
                <li class="breadcrumb-item active">Director Appointments</li>
            </ol>
        </nav>
        <div class="d-flex justify-content-between align-items-center">
            <h1 class="h3">
                <i class="bi bi-people"></i> Director Appointments
            </h1>
            <div class="btn-group">
                <a href="{{ route('companies.appointments.create', $company) }}" class="btn btn-primary">
                    <i class="bi bi-plus-lg"></i> Add Appointment
                </a>
                <a href="{{ route('companies.export-directors-docx', $company) }}" class="btn btn-info">
                    <i class="bi bi-file-earmark-word"></i> Export DOCX
                </a>
            </div>
        </div>
    </div>
</div>

<div class="card mb-4">
    <div class="card-header bg-light">
        <h5 class="mb-0">
            <i class="bi bi-building"></i> {{ $company->company_name }}
            <small class="text-muted">(CI: {{ $company->ci_number }})</small>
        </h5>
    </div>
</div>

<div class="card">
    <div class="card-body">
        @if($appointments->isEmpty())
            <div class="text-center py-5 text-muted">
                <i class="bi bi-people fs-1"></i>
                <p class="mt-3">No director appointments found for this company.</p>
                <a href="{{ route('companies.appointments.create', $company) }}" class="btn btn-primary">
                    <i class="bi bi-plus-lg"></i> Add First Appointment
                </a>
            </div>
        @else
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>Director Name / 董事姓名</th>
                            <th>Date of Appointment / 委任日期</th>
                            <th>Date of Ceasing / 離職日期</th>
                            <th>Status</th>
                            <th>Remarks / 備註</th>
                            <th class="text-end">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($appointments as $appointment)
                            <tr>
                                <td>
                                    <a href="{{ route('directors.show', $appointment->director) }}">
                                        {{ $appointment->director->full_name }}
                                    </a>
                                </td>
                                <td>{{ $appointment->date_of_appointment->format('d/m/Y') }}</td>
                                <td>{{ $appointment->date_of_ceasing ? $appointment->date_of_ceasing->format('d/m/Y') : '-' }}</td>
                                <td>
                                    @if($appointment->date_of_ceasing)
                                        <span class="badge bg-secondary">Ceased</span>
                                    @else
                                        <span class="badge bg-success">Active</span>
                                    @endif
                                </td>
                                <td>{{ Str::limit($appointment->remarks, 30) ?? '-' }}</td>
                                <td class="text-end">
                                    <div class="btn-group btn-group-sm">
                                        <a href="{{ route('companies.appointments.edit', [$company, $appointment]) }}" class="btn btn-outline-secondary" title="Edit">
                                            <i class="bi bi-pencil"></i>
                                        </a>
                                        <form action="{{ route('companies.appointments.destroy', [$company, $appointment]) }}" method="POST" class="d-inline" onsubmit="return confirm('Are you sure you want to delete this appointment?');">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="btn btn-outline-danger btn-sm" title="Delete">
                                                <i class="bi bi-trash"></i>
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        @endif
    </div>
</div>

<div class="mt-4">
    <a href="{{ route('companies.show', $company) }}" class="btn btn-secondary">
        <i class="bi bi-arrow-left"></i> Back to Company
    </a>
</div>
@endsection