import 'dart:async';

import 'package:flutter/material.dart';
import 'package:frontend_eccp_mobile/app/core/constants/app_colors.dart';
import 'package:frontend_eccp_mobile/app/core/constants/app_text_styles.dart';
import 'package:frontend_eccp_mobile/app/core/widgets/layout/app_screen.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return const HomeUI();
  }
}

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

  @override
  State<HomeUI> createState() => _HomeUIState();
}

class _HomeUIState extends State<HomeUI> {
  final RefreshController _refreshController = RefreshController();

  Future<void> _onRefresh() async {
    onInit();
    await Future<dynamic>.delayed(const Duration(seconds: 1));
    _refreshController.refreshCompleted();
  }

  void onInit() {}

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

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

  @override
  Widget build(BuildContext context) {
    return AppScreen(
      backgroundColor: AppColors.neutralWhite,
      refreshController: _refreshController,
      enablePullDown: true,
      onRefresh: _onRefresh,
      refreshHeader: const ClassicHeader(),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Center(
            child: Text('Home Page', style: AppTextStyles.h4),
          ),
        ],
      ),
    );
  }
}
