import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_event.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';

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

  @override
  Widget build(BuildContext context) {
    DateTime now = DateTime.now();
    DateTime cleaned =
        DateTime(now.year, now.month, now.day, now.hour, now.minute);
    return DefaultContainer(
        padding: const EdgeInsets.all(20),
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  child: Container(
                    padding: const EdgeInsets.all(10.0),
                    child: const BodyMedium(
                      text: 'Password Name',
                      fontWeight: FontWeight.normal,
                    ),
                  ),
                ),
                SizedBox(
                    width: MediaQuery.of(context).size.width / 2.6,
                    child: TextFormField(
                      controller: BlocProvider.of<SmartDoorBloc>(context)
                          .passwordNameController,
                      decoration: const InputDecoration(
                          hintText: 'Enter The Name',
                          hintStyle: TextStyle(
                              fontSize: 14, color: ColorsManager.textGray)),
                    )),
              ],
            ),
            Column(
              children: [
                const Divider(
                  color: ColorsManager.graysColor,
                ),
                Padding(
                  padding: const EdgeInsets.all(10.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      const Expanded(
                        child: BodyMedium(
                          text: 'Effective Time',
                          fontWeight: FontWeight.normal,
                        ),
                      ),
                      SizedBox(
                          width: MediaQuery.of(context).size.width / 3.5,
                          child: InkWell(
                            onTap: () {
                              BlocProvider.of<SmartDoorBloc>(context).add(
                                  SelectTimeOnlinePasswordEvent(
                                      context: context, isEffective: true));
                            },
                            child: Text(
                              BlocProvider.of<SmartDoorBloc>(context)
                                          .effectiveTime ==
                                      'Select Time'
                                  ? cleaned.toString()
                                  : BlocProvider.of<SmartDoorBloc>(context)
                                      .effectiveTime,
                              style: TextStyle(fontSize: 14),
                            ),
                          )),
                    ],
                  ),
                ),
                const Divider(
                  color: ColorsManager.graysColor,
                ),
                Padding(
                  padding: const EdgeInsets.all(10.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      const Expanded(
                        child: BodyMedium(
                          text: 'Expiration Time',
                          fontWeight: FontWeight.normal,
                        ),
                      ),
                      SizedBox(
                        width: MediaQuery.of(context).size.width / 3.5,
                        child: InkWell(
                          onTap: () {
                            BlocProvider.of<SmartDoorBloc>(context).add(
                                SelectTimeOnlinePasswordEvent(
                                    context: context, isEffective: false));
                          },
                          child: Text(
                            BlocProvider.of<SmartDoorBloc>(context)
                                .expirationTime,
                            style: TextStyle(
                                fontSize: 14,
                                color: BlocProvider.of<SmartDoorBloc>(context)
                                            .expirationTime ==
                                        'Select Time'
                                    ? ColorsManager.textGray
                                    : null),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ],
        ));
  }
}
