import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart';
import 'package:syncrow_web/pages/routines/models/gateway.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialog_function_list_tile.dart';
import 'package:syncrow_web/utils/color_manager.dart';

class GatewayFunctionsList extends StatelessWidget {
  const GatewayFunctionsList({
    required this.gatewayFunctions,
    super.key,
  });

  final List<GatewayFunctions> gatewayFunctions;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: 360,
      child: ListView.separated(
        shrinkWrap: false,
        itemCount: gatewayFunctions.length,
        separatorBuilder: (context, index) => const Padding(
          padding: EdgeInsets.symmetric(horizontal: 40.0),
          child: Divider(color: ColorsManager.dividerColor),
        ),
        itemBuilder: (context, index) {
          final function = gatewayFunctions[index];
          return RoutineDialogFunctionListTile(
            iconPath: function.icon,
            operationName: function.operationName,
            onTap: () => context.read<FunctionBloc>().add(
                  SelectFunction(
                    functionCode: function.code,
                    operationName: function.operationName,
                  ),
                ),
          );
        },
      ),
    );
  }
}
