import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

import 'package:pshared/provider/recipient/pmethods.dart';

import 'package:pweb/pages/payment_methods/manage/method_tile.dart';
import 'package:pweb/controllers/payments/payment_config.dart';


class PaymentConfigList extends StatelessWidget {
  final PaymentConfigController controller;
  const PaymentConfigList({super.key, required this.controller});

  @override
  Widget build(BuildContext context) {
    final provider = context.watch<PaymentMethodsProvider>();

    return ReorderableListView.builder(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemCount: provider.methods.length,
      onReorder: controller.reorder,
      itemBuilder: (context, index) {
        final method = provider.methods[index];
        return ReorderableDragStartListener(
          key: Key(method.id),
          index: index,
          child: PaymentMethodTile(
            method: method,
            index: index,
            makeMain: () => controller.makeMain(method),
            toggleEnabled: (v) => controller.toggleEnabled(method, v),
            edit: () => controller.editMethod(method),
            delete: () => controller.deleteMethod(method),
          ),
        );
      },
    );
  }
}