// Version: 1.0.0 | Created: 2026-04-10
// Embedded conference join widget for the bottom nav tab.

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

/// Inline widget shown inside the RoomsScreen bottom nav.
/// Lets authenticated users paste a Jitsi meeting link and join.
class ConferenceTab extends StatefulWidget {
  const ConferenceTab({super.key});

  @override
  State<ConferenceTab> createState() => _ConferenceTabState();
}

class _ConferenceTabState extends State<ConferenceTab> {
  final _linkController = TextEditingController();

  @override
  void dispose() {
    _linkController.dispose();
    super.dispose();
  }

  void _joinConference() {
    final link = _linkController.text.trim();
    if (link.isEmpty) {
      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(content: Text('Please paste a meeting link.')),
      );
      return;
    }
    context.push('/jitsi', extra: link);
  }

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    return Center(
      child: SingleChildScrollView(
        padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 24),
        child: ConstrainedBox(
          constraints: const BoxConstraints(maxWidth: 440),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Icon(
                Icons.videocam_outlined,
                size: 64,
                color: theme.colorScheme.primary.withAlpha(180),
              ),
              const SizedBox(height: 16),
              Text(
                'Join a Conference',
                style: theme.textTheme.titleLarge?.copyWith(
                  fontWeight: FontWeight.bold,
                ),
              ),
              const SizedBox(height: 8),
              Text(
                'Paste your meeting link below to join.',
                style: theme.textTheme.bodyMedium?.copyWith(
                  color: theme.colorScheme.onSurface.withAlpha(153),
                ),
              ),
              const SizedBox(height: 32),
              TextField(
                controller: _linkController,
                decoration: const InputDecoration(
                  hintText: 'conf.m8chat.au/YourMeeting',
                  prefixIcon: Icon(Icons.link),
                  border: OutlineInputBorder(),
                ),
                textInputAction: TextInputAction.go,
                onSubmitted: (_) => _joinConference(),
              ),
              const SizedBox(height: 16),
              SizedBox(
                width: double.infinity,
                child: ElevatedButton.icon(
                  onPressed: _joinConference,
                  icon: const Icon(Icons.videocam),
                  label: const Text('Join Meeting'),
                  style: ElevatedButton.styleFrom(
                    minimumSize: const Size.fromHeight(52),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
