import 'package:app/global/theme/base/app_theme_ext.dart';
import 'package:app/providers/user_store.dart';
import 'package:app/router/route_paths.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import 'package:remixicon/remixicon.dart';

class Header extends StatelessWidget implements PreferredSizeWidget {
  const Header({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: SafeArea(
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: context.pagePadding),
          height: preferredSize.height,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    "学光自习室",
                    style: Theme.of(context).textTheme.titleSmall,
                  ),
                  Text(
                    "在线陪伴、用心教学",
                    style: Theme.of(context).textTheme.labelMedium,
                  ),
                ],
              ),
              Row(
                children: [
                  PopupMenuButton(
                    color: Colors.white,
                    padding: EdgeInsets.zero,
                    position: PopupMenuPosition.under,
                    onSelected: (value) {
                      if (value == 1) {
                        UserStore userStore = context.read<UserStore>();
                        userStore.logout();
                        context.go(RoutePaths.login);
                      }
                    },
                    itemBuilder: (context) => [
                      PopupMenuItem(
                        value: 1,
                        child: Text("退出登录", textAlign: TextAlign.center),
                      ),
                    ],
                    child: IconButton(
                      onPressed: null,
                      icon: Icon(RemixIcons.user_line),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }

  @override
  Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
