import 'package:flutter/material.dart';
import 'package:garage/car/page/my_garage_page.dart';
import 'package:garage/user/widget/settings_box.dart';

import '../../auth/widget/login_page.dart';
import '../widget/change_password.dart';
import '../widget/user_info_tile.dart';

class UserPage extends StatelessWidget {
  const UserPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(children: [
        UserInfoTile(),
        SettingsBox(children: [
          _buildClickableRow(
              context,
              () => Navigator.of(context).push(MaterialPageRoute(
                  builder: (context) => MyGaragePage(showArchived: true))),
              [
                Icon(Icons.archive_outlined),
                _buildSettingsText("Archivovaná vozidla"),
                Spacer(),
                Icon(Icons.chevron_right_sharp, size: 30)
              ]),
        ]),
        Spacer(),
        SettingsBox(children: [
          _buildClickableRow(
              context,
              () => Navigator.push(context,
                  MaterialPageRoute(builder: (context) => ChangePassword())),
              [
                Icon(Icons.published_with_changes),
                _buildSettingsText("Změnit heslo"),
                Spacer(),
                Icon(Icons.chevron_right_sharp, size: 30)
              ]),
          Divider(height: 0),
          _buildClickableRow(context, LoginPage.logoutUser, [
            Icon(Icons.logout),
            _buildSettingsText("Odhlásit se"),
            Spacer(),
            Icon(Icons.chevron_right_sharp, size: 30)
          ]),
        ]),
      ]),
    );
  }

  Widget _buildClickableRow(context, VoidCallback onTap, children) {
    return InkWell(
        onTap: onTap,
        child: Padding(
          padding:
              const EdgeInsets.only(left: 8.0, right: 8, top: 3, bottom: 3),
          child: Row(children: children),
        ));
  }

  Widget _buildSettingsText(String text) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Text(
        text,
        style: TextStyle(fontSize: 20),
      ),
    );
  }
}
