import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart';
import 'package:farm_tpf/presentation/custom_widgets/button/second_button.dart';
import 'package:farm_tpf/presentation/screens/codes/update_activity_page.dart';
import 'package:farm_tpf/presentation/screens/codes/widgets/item_code_timeline.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../themes/styles_text.dart';

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

  @override
  State<CodeDetailPage> createState() => _CodeDetailPageState();
}

class _CodeDetailPageState extends State<CodeDetailPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarWidget(
        action: IconButton(
          onPressed: () {
            Get.to(() => UpdateActivityPage(
                  stampCode: 'AC_494D9D90',
                ));
          },
          icon: Icon(
            Icons.edit,
            color: Colors.blue,
          ),
        ),
      ),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          children: [
            Expanded(
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    _itemCodeDetail(
                      title: 'Tên sản phẩm',
                      detail: 'Cà rốt',
                      titleStyle: StylesText.body4,
                      detailStyle: StylesText.body4.copyWith(
                        color: Colors.blue,
                      ),
                    ),
                    _itemCodeDetail(title: 'Mô tả', detail: 'detail'),
                    _itemCodeDetail(title: 'Số lượng tem', detail: 'detail'),
                    _itemCodeDetail(title: 'Trạng thái', detail: 'detail'),
                    _itemCodeDetail(title: 'Hạn sử dụng', detail: 'detail'),
                    _itemCodeDetail(title: 'Mẫu tem', detail: 'detail'),
                    Text(
                      'Timeline hoạt động',
                      style: StylesText.body1,
                    ),
                    _timelineWidget(),
                  ],
                ),
              ),
            ),
            const SizedBox(
              height: 8,
            ),
            // Container(
            //   width: 100,
            //   height: 100,
            //   color: Colors.red,
            // ),
            _actionButtonWidget(),
          ],
        ),
      ),
    );
  }

  Widget _timelineWidget() {
    return ListView.builder(
      itemBuilder: (context, index) {
        return ItemCodeTimeline(
          onPressed: () {},
        );
      },
      itemCount: 20,
      physics: NeverScrollableScrollPhysics(),
      shrinkWrap: true,
    );
  }

  Widget _actionButtonWidget() {
    return Wrap(
      spacing: 8,
      children: [
        Row(
          children: [
            Expanded(
              child: SecondButton(
                onPressed: () {},
                title: 'Kích hoạt toàn bộ',
                borderColor: Colors.blue,
                textColor: Colors.blue,
                width: double.infinity,
                height: 40,
              ),
            ),
            Expanded(
              child: SecondButton(
                onPressed: () {},
                title: 'Huỷ toàn bộ',
                borderColor: Colors.red,
                textColor: Colors.white,
                color: Colors.red,
                width: double.infinity,
                height: 40,
              ),
            ),
          ],
        ),
        const SizedBox(
          height: 8,
        ),
        Row(
          children: [
            Expanded(
              child: SecondButton(
                onPressed: () {},
                title: 'Cập nhật hoạt động',
                borderColor: Colors.green,
                textColor: Colors.green,
                width: double.infinity,
                height: 40,
              ),
            ),
            Expanded(
              child: SecondButton(
                onPressed: () {},
                title: 'In / Xuất file',
                borderColor: Colors.cyan,
                textColor: Colors.white,
                color: Colors.cyan,
                width: double.infinity,
                height: 40,
              ),
            ),
          ],
        ),
      ],
    );
  }

  Widget _itemCodeDetail({
    required String title,
    required String detail,
    TextStyle? titleStyle,
    TextStyle? detailStyle,
  }) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
      child: Row(
        children: [
          Expanded(
            child: Text(
              title,
              style: titleStyle ?? StylesText.body6,
            ),
          ),
          Text(
            detail,
            style: detailStyle ?? StylesText.body6,
          )
        ],
      ),
    );
  }
}
