import 'package:flutter/material.dart';
import '/widgets/widgets.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../themes/themes.dart';
import '../../viewmodels/viewmodels.dart';
import '../pedido/pedido_sync.dart';

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

  @override
  Formulario createState() => Formulario();
}

class Formulario extends State<HomeScreen> {
  @override
  void initState() {
    super.initState();
    // Future(() async {
    //   await Provider.of<LoginViewModel>(context, listen: false).setValores();
    // });
    PedidoSync().startSync(Provider.of<PedidoViewModel>(context, listen: false),
        Provider.of<CorteCajaViewModel>(context, listen: false));

    WidgetsBinding.instance.addPostFrameCallback((_) {
      Provider.of<ProductoViewModel>(context, listen: false)
          .sincronizarProductosYCategorias();

      Provider.of<MesaViewModel>(context, listen: false).sincronizarMesas();

      final permisoViewModel =
          Provider.of<PermisoViewModel>(context, listen: false);
      if (permisoViewModel.userPermisos.isEmpty) {
        permisoViewModel.fetchUserPermisos();
      }

      Provider.of<CorteCajaViewModel>(context, listen: false).fetchCortes();
      Provider.of<MesaViewModel>(context, listen: false)
          .fetchLocalAll(sinLimite: true);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey.shade200,
      drawer: AppDrawer(),
      appBar: AppBar(
        title: Text(
          'Inicio',
          style: TextStyle(color: AppTheme.secondary),
        ),
        iconTheme: IconThemeData(color: AppTheme.secondary),
      ),
      body: const Center(
        child: Image(
          image: AssetImage('assets/logo.png'),
          height: 200,
        ),
      ),
    );
  }
}
