import 'package:flutter/material.dart';
import '../../login/views/login_page.dart';
import '../models/onboarding_model.dart';
import 'widgets/glass_card.dart';

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

  @override
  State<OnboardingPage> createState() => _OnboardingPageState();
}

class _OnboardingPageState extends State<OnboardingPage> {
  int currentIndex = 0;

  final List<OnboardingModel> onboardingData = [
    OnboardingModel(
      image: 'assets/onboarding/bg.png',
      title: 'What we do',
      description:
      'Easily manage and promote your attractions while connecting with travelers and handling bookings in one place.',
    ),
    OnboardingModel(
      image: 'assets/onboarding/bg2.png',
      title: 'Manage Booking Seamlessly',
      description:
      'Track and manage all your bookings in real-time from one easy-to-use dashboard.',
    ),
  ];



  void _nextPage() {
    if (currentIndex == onboardingData.length - 1) {
      // 👇 Navigate to LoginPage after last screen
      Navigator.pushReplacement(
        context,
        MaterialPageRoute(builder: (context) => const LoginPage()),
      );
    } else {
      setState(() {
        currentIndex++;
      });
    }
  }

  void _skip() {
    // 👇 Navigate to LoginPage when skipping
    Navigator.pushReplacement(
      context,
      MaterialPageRoute(builder: (context) => const LoginPage()),
    );
  }
  @override
  Widget build(BuildContext context) {
    final current = onboardingData[currentIndex];

    return Scaffold(
      body: Stack(
        fit: StackFit.expand,
        children: [
          Image.asset(current.image, fit: BoxFit.cover),
          current.title == "Manage Booking Seamlessly"
              ? Container()
              : SafeArea(
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Align(
                alignment: Alignment.topRight,
                child: OutlinedButton(
                  onPressed: () {
                    _skip();
                  },
                  style: OutlinedButton.styleFrom(
                    side: const BorderSide(color: Colors.white),
                    foregroundColor: Colors.white,
                    padding: const EdgeInsets.symmetric(
                      horizontal: 20,
                      vertical: 8,
                    ),
                  ),
                  child: const Text("Skip"),
                ),
              ),
            ),
          ),
          Align(
            alignment: Alignment.bottomCenter,
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: GlassCard(
                title: current.title,
                description: current.description,
                currentIndex: currentIndex,
                total: onboardingData.length,
                onContinue: _nextPage,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
