import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/devices/model/schedule_model.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/empty_schedule.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/generated/assets.dart';

class CirculateListView extends StatelessWidget {
  final List<ScheduleModel> listSchedule;
  final Function(String) onDismissed;
  final Function(String, bool) onToggleSchedule;
  const CirculateListView({
    super.key,
    required this.listSchedule,
    required this.onDismissed,
    required this.onToggleSchedule,
  });

  @override
  Widget build(BuildContext context) {
    return Center(
        child: listSchedule.isNotEmpty
            ? SizedBox(
                child: ListView.builder(
                  shrinkWrap: true,
                  itemCount: listSchedule.length,
                  itemBuilder: (context, index) {
                    return Dismissible(
                      key: Key(listSchedule[index].scheduleId),
                      background: Container(
                        padding: const EdgeInsets.only(right: 10),
                        alignment: AlignmentDirectional.centerEnd,
                        decoration: const ShapeDecoration(
                          color: Color(0xFFFF0000),
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.all(Radius.circular(20)),
                          ),
                        ),
                        child: Padding(
                          padding: const EdgeInsets.only(bottom: 10, right: 10),
                          child: SvgPicture.asset(
                            Assets.assetsDeleteIcon,
                            width: 20,
                            height: 22,
                          ),
                        ),
                      ),
                      direction: DismissDirection.endToStart,
                      onDismissed: (direction) {
                        onDismissed(listSchedule[index].scheduleId);

                        ScaffoldMessenger.of(context).showSnackBar(
                          const SnackBar(content: Text('Schedule removed')),
                        );
                      },
                      child: InkWell(
                        onTap: () {},
                        child: DefaultContainer(
                          padding: const EdgeInsets.all(20),
                          height: MediaQuery.of(context).size.height / 6.5,
                          child: Row(
                            children: [
                              Expanded(
                                flex: 2,
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Row(
                                      children: [
                                        BodyLarge(
                                          text: '12:30 AM - 01:30 PM',
                                          // text: listSchedule[index].time,
                                          fontWeight: FontWeight.w500,
                                          fontColor: Colors.black,
                                          fontSize: 18,
                                        ),
                                      ],
                                    ),
                                    Text(listSchedule[index].days.join(' ')),
                                    // Text('Function ${listSchedule[index].function.value ? "ON" : "OFF"}'),
                                    Text(
                                        'Start Duration: 0h 10m  End Duration: 0h 15m'),
                                  ],
                                ),
                              ),
                              Expanded(
                                child: ListTile(
                                  contentPadding: EdgeInsets.zero,
                                  leading: const BodyMedium(
                                    text: '',
                                    fontWeight: FontWeight.normal,
                                  ),
                                  trailing: Transform.scale(
                                    scale: .8,
                                    child: CupertinoSwitch(
                                      value: listSchedule[index].enable,
                                      onChanged: (value) {
                                        onToggleSchedule(
                                          listSchedule[index].scheduleId,
                                          value,
                                        );
                                      },
                                      applyTheme: true,
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    );
                  },
                ),
              )
            : const EmptySchedule());
  }
}
