import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:namer_app/databug.dart';
import 'package:namer_app/footer.dart';
import 'package:namer_app/head.dart';
import 'package:namer_app/header.dart';

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // appBar: Header(
      //   title: Text('title'),
      //   appBar: AppBar(),
      //   widgets: <Widget>[Icon(Icons.more_vert)],
      // ),
      appBar: CustomAppbar(),
      body: Stack(children: [
        SingleChildScrollView(
          child: Column(
            children: [
              Center(
                  child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'LIST BUG',
                    style: TextStyle(color: Colors.black, fontSize: 48),
                  ),
                ],
              )),
              Column(
                children: List.generate(
                    2,
                    (i) => SizedBox(
                          // height: 80,
                          child: ListTile(
                            // visualDensity: VisualDensity(vertical: 4),
                            leading: SizedBox(
                              child: Icon(Icons.bug_report),
                            ),
                            title: Text(bugs[i]['bug']),
                            subtitle: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(bugs[i]['goodday']),
                                Row(
                                  children: [
                                    Text(bugs[i]['created']),
                                    Container(
                                      width: 30,
                                    ),
                                    Text(bugs[i]['level']),
                                  ],
                                ),
                                Row(
                                  children: [
                                    Text(bugs[i]['qc']),
                                    Container(
                                      width: 20,
                                    ),
                                    Text(bugs[i]['status']),
                                    Container(
                                      width: 20,
                                    ),
                                    Text(bugs[i]['programmer']),
                                    Container(
                                      width: 20,
                                    ),
                                    Text(bugs[i]['dev_status'])
                                  ],
                                )
                              ],
                            ),
                            trailing: ButtonUser(
                              items: bugs[i],
                            ),
                          ),
                        )),
              ),
            ],
          ),
        ),
      ]),
      bottomNavigationBar: Footer(),
    );
  }
}

class ButtonUser extends StatelessWidget {
  final Map<String, dynamic> items;
  ButtonUser({
    required this.items,
    super.key,
  });
  //todo tombol item
  //todo tombol delete
  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        ElevatedButton(
          onPressed: () => context.go('/login/bug/editbug'),
          style: ElevatedButton.styleFrom(
            backgroundColor: Colors.black,
          ),
          child: Text(
            'Edit',
            style: TextStyle(color: Colors.white),
          ),
        ),
        ElevatedButton(
          onPressed: null,
          style: ElevatedButton.styleFrom(
            backgroundColor: Colors.black,
          ),
          child: Text(
            'Delete',
            style: TextStyle(color: Colors.white),
          ),
        ),
        ElevatedButton(
          onPressed: () => context.go('/login/bug/comment'),
          style: ElevatedButton.styleFrom(
            backgroundColor: Colors.black,
          ),
          child: Text(
            'Comment',
            style: TextStyle(color: Colors.white),
          ),
        ),
      ],
    );
  }
}