import 'dart:io';

import 'package:eitc_erm_app/select_clinic.dart';
import 'package:eitc_erm_app/utils/Constants.dart';
import 'package:eitc_erm_app/utils/Share.dart';
import 'package:eitc_erm_app/utils/Utils.dart';
import 'package:flutter/material.dart';

import 'bottom_navigation.dart';
import 'doctor_talk_list.dart';
import 'login.dart';
import 'package:http/http.dart' as http;

void main() {
  runApp(Main());
}

class Main extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: SplashScreen(),
      routes: {
        '/login': (context) => Login(),
        '/home': (context) => BottomNavigationWidget(),
        '/doctor': (context) => DoctorTalkList(),
        '/selectClinic': (context) => SelectClinic(""),
      },
    );
  }
}

class SplashScreen extends StatefulWidget {
  @override
  _SplashScreenState createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {
  @override
  void initState() {
    super.initState();
    // 在这里可以进行一些初始化操作，如加载数据等
    // 通过Future.delayed方法模拟加载时间
    Future.delayed(Duration(seconds: 3), () async {
      /*if(!(await Utils.readData("token")).isEmpty) {
        Global.token = await Utils.readData("token");
        Navigator.pushReplacementNamed(context, '/home');
      } else if(!(await Utils.readData("doctorToken")).isEmpty) {
        Global.token = await Utils.readData("doctorToken");
        Navigator.pushReplacementNamed(context, '/doctor');
      } else
        Navigator.pushReplacementNamed(context, '/login');*/
      Navigator.pushReplacementNamed(context, '/selectClinic');
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            FlutterLogo(
              size: 100,
            ),
            SizedBox(height: 16),
            Text(
              '智慧口腔诊所',
              style: TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              ),
            ),
            SizedBox(height: 16),
            CircularProgressIndicator(),
          ],
        ),
      ),
    );
  }
}
