import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import 'package:tm_app/core/constants/assets.dart';
import 'package:tm_app/core/theme/colors.dart';
import 'package:tm_app/core/utils/size_config.dart';
import 'package:tm_app/views/shared/base_button.dart';
import 'package:tm_app/views/tenders/strings/tenders_strings.dart';

import '../../../view_models/tenders_view_model.dart';

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

  @override
  Widget build(BuildContext context) {
    return Consumer<TendersViewModel>(
      builder: (context, vm, child) {
        return SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.all(16),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Text(
                      TendersStrings.sort,
                      style: TextStyle(
                        fontSize: 20.0.sp(),
                        fontWeight: FontWeight.w700,
                        color: AppColors.grey70,
                      ),
                    ),
                    const Spacer(),
                    InkWell(
                      onTap: () => Navigator.pop(context),
                      child: SvgPicture.asset(
                        AssetsManager.closeCircle,
                        colorFilter: ColorFilter.mode(
                          AppColors.grey80,
                          BlendMode.srcIn,
                        ),
                        width: 24.0.w(),
                        height: 24.0.h(),
                      ),
                    ),
                  ],
                ),
                SizedBox(height: 16.0.h()),
                Divider(color: AppColors.grey20),
                SizedBox(height: 20.0.h()),
                ...[
                  TendersStrings.minimumTime,
                  TendersStrings.mostOfTheTime,
                  TendersStrings.lessBudget,
                  TendersStrings.moreBudget,
                ].map((status) {
                  return RadioListTile(
                    value: status,
                    groupValue: vm.selectedSort,
                    activeColor: AppColors.mainBlue,
                    onChanged: (value) => vm.setSort(value!),
                    title: Text(
                      status,
                      style: TextStyle(
                        fontSize: 16.0.sp(),
                        fontWeight: FontWeight.w400,
                        color: AppColors.grey70,
                      ),
                    ),
                  );
                }),
                SizedBox(height: 16.0.h()),
                Row(
                  children: [
                    const Spacer(),
                    SizedBox(
                      width: 156.0.w(),
                      child: BaseButton(
                        isEnabled: true,
                        onPressed: () {
                          context.pop();
                          vm.callWithSortAndStatus();
                        },
                        text: TendersStrings.confirm,
                        textColor: AppColors.textBlue,
                        backgroundColor: AppColors.primary2,
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
