import 'package:cheminova/screens/data_submit_successfull.dart';
import 'package:cheminova/widgets/common_drawer.dart';
import 'package:flutter/material.dart';
import 'package:cheminova/widgets/common_background.dart';
import 'package:intl/intl.dart';
import '../widgets/common_app_bar.dart';
import '../widgets/common_elevated_button.dart';
import '../widgets/common_text_form_field.dart';

// Screen for entering product purchase data
class ProductPurchaseData extends StatefulWidget {
  const ProductPurchaseData({super.key});

  @override
  State<ProductPurchaseData> createState() => ProductPurchaseDataState();
}

class ProductPurchaseDataState extends State<ProductPurchaseData> {
  final dateController = TextEditingController(
      text: DateFormat('dd/MM/yyyy').format(DateTime.now())); // Initialize date controller with current date

  final timeController =
  TextEditingController(text: DateFormat('hh:mm a').format(DateTime.now())); // Initialize time controller with current time

  // Controllers for other input fields
  final locationController = TextEditingController();
  final notesController = TextEditingController();
  final dealercontroller = TextEditingController();
  final productController = TextEditingController();
  final qualityController = TextEditingController();
  final salesController = TextEditingController();
  final commentController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return CommonBackground(
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: CommonAppBar(
          actions: [
            IconButton(
              onPressed: () {
                Navigator.pop(context); // Navigate back to the previous screen
              },
              icon: Image.asset('assets/Back_attendance.png'),
              padding: const EdgeInsets.only(right: 20),
            ),
          ],
          title: const Text('Product Purchase Data',
              style: TextStyle(
                  fontSize: 20,
                  color: Colors.black,
                  fontWeight: FontWeight.w400,
                  fontFamily: 'Anek')),
          backgroundColor: Colors.transparent,
          elevation: 0,
        ),
        drawer: const CommonDrawer(),
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: SingleChildScrollView(
            physics: const BouncingScrollPhysics(),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                const SizedBox(height: 16),
                Container(
                  padding:
                  const EdgeInsets.all(20.0).copyWith(top: 30, bottom: 30),
                  decoration: BoxDecoration(
                      border: Border.all(color: Colors.white),
                      color: const Color(0xffB4D1E5).withOpacity(0.9),
                      borderRadius: BorderRadius.circular(26.0)),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      // Input field for selecting a dealer
                      CommonTextFormField(
                          title: 'Select Dealer: Dealer 1',
                          fillColor: Colors.white,
                          controller: dealercontroller),
                      const SizedBox(height: 15),

                      // Input field for selecting a product
                      CommonTextFormField(
                          title: 'Select Product: Product A',
                          fillColor: Colors.white,
                          controller: productController),
                      const SizedBox(height: 15),

                      // Read-only input field for date range
                      CommonTextFormField(
                          title: 'Date Range: 10-06 to 20-06',
                          readOnly: true,
                          fillColor: Colors.white,
                          controller: dateController),
                      const SizedBox(height: 15),

                      // Button to view data, navigates to the success screen on press
                      Align(
                        alignment: Alignment.center,
                        child: CommonElevatedButton(
                          borderRadius: 30,
                          width: double.infinity,
                          height: kToolbarHeight - 10,
                          text: 'VIEW DATA',
                          backgroundColor: const Color(0xff004791),
                          onPressed: () => Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) => const DataSubmitSuccessFullScreen(),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
