import 'package:flutter/material.dart';
import 'dart:async';
import 'auth_wrapper.dart';

class TerminalBootScreen extends StatefulWidget {
  const TerminalBootScreen({super.key});

  @override
  State<TerminalBootScreen> createState() => _TerminalBootScreenState();
}

class _TerminalBootScreenState extends State<TerminalBootScreen> {
  final List<String> _lines = [];
  final List<String> _allMessages = [
    "> INITIALIZING SAVEXSTATE™ OS...",
    "> CONNECTING TO SAGE_NET...",
    "> LOADING ENCRYPTION_KEYS...",
    "> SCANNING_BIOMETRICS...",
    "> ACCESS_GRANTED.",
    "> WELCOME TO THE VAULT.",
  ];

  @override
  void initState() {
    super.initState();
    _startBootSequence();
  }

  void _startBootSequence() async {
    for (String msg in _allMessages) {
      await Future.delayed(const Duration(milliseconds: 500));
      if (mounted) setState(() => _lines.add(msg));
    }
    await Future.delayed(const Duration(seconds: 1));
    if (mounted) {
      Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const AuthWrapper()));
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: Padding(
        padding: const EdgeInsets.all(30.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Center(child: Image.asset('assets/images/logo.png', height: 120, color: const Color(0xFFE87D25))),
            const SizedBox(height: 50),
            ..._lines.map((line) => Text(line, style: const TextStyle(color: Color(0xFFE87D25), fontSize: 13))),
          ],
        ),
      ),
    );
  }
}