@extends('admin.layout')

@section('title', 'Sessions')

@section('content')
<div class="pg-head">
    <div>
        <h1>Sessions</h1>
        <p>Manage event sessions and schedules.</p>
    </div>
    <div class="pg-actions">
        <a href="{{ route('mexco.admin.sessions.create') }}" class="btn-purple">+ Create New Session</a>
        @if($event->sessions->count() > 0)
            <a href="{{ route('mexco.admin.sessions.tentative') }}" class="btn-outline" target="_blank">Generate Event Tentative</a>
        @endif
    </div>
</div>

<div class="card">
    <div class="tbl-wrap">
        <table class="data-tbl">
            <thead>
                <tr>
                    <th>Session Title</th>
                    <th>Speaker</th>
                    <th>Date &amp; Time</th>
                    <th>Status</th>
                    <th style="text-align:right">Actions</th>
                </tr>
            </thead>
            <tbody>
                @forelse($sessions as $s)
                    <tr>
                        <td><span class="link-title">{{ $s->title }}</span></td>
                        <td><span class="cell-sub">{{ $s->speaker ?: '-' }}</span></td>
                        <td>
                            <span class="cell-sub">{{ $s->day->format('d M Y') }}<br>{{ $s->time }}</span>
                            @if($s->is_parallel)
                                <span class="status-pill status-scheduled d-inline-block mt-1">Parallel</span>
                            @endif
                        </td>
                        <td>
                            <form method="POST" action="{{ route('mexco.admin.sessions.toggle-publish', $s) }}">
                                @csrf
                                <button type="submit"
                                    class="status-toggle {{ $s->is_published ? 'is-active' : '' }}"
                                    title="{{ $s->is_published ? 'Unpublish session' : 'Publish session' }}">
                                    <span class="status-toggle-track" aria-hidden="true"></span>
                                    <span class="status-toggle-label">{{ $s->is_published ? 'Published' : 'Unpublished' }}</span>
                                </button>
                            </form>
                        </td>
                        <td>
                            <div class="tbl-actions">
                                <a href="{{ route('mexco.admin.sessions.edit', $s) }}" class="icon-btn" title="Edit">
                                    <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M12 20h9M16.5 3.5a2.1 2.1 0 013 3L7 19l-4 1 1-4 12.5-12.5z"/></svg>
                                </a>
                                <form method="POST" action="{{ route('mexco.admin.sessions.destroy', $s) }}"
                                      onsubmit="return confirm('Delete session {{ $s->session_key }} - {{ $s->title }}?')">
                                    @csrf @method('DELETE')
                                    <button type="submit" class="icon-btn danger" title="Delete">
                                        <svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M3 6h18M8 6V4h8v2M6 6l1 14h10l1-14"/></svg>
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="5" style="text-align:center;padding:3rem;color:var(--muted)">No sessions yet.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <div class="tbl-foot">
        <span>Showing {{ $sessions->count() ? 1 : 0 }} to {{ $sessions->count() }} of {{ $sessions->count() }} entries</span>
        <div class="pager"><span class="on">1</span></div>
    </div>
</div>
@endsection
