// ignore_for_file: use_build_context_synchronously
import 'dart:convert';
import 'package:provider/provider.dart';
import '../Ad6_viewModel/Ad6_view_model_screen.dart';
import 'package:base_project/BuilderField/shared/ui/entity_screens.dart';
import 'Ad6_fields.dart';import '../../../../utils/image_constant.dart';
import '../../../../utils/size_utils.dart';
import '../../../../theme/app_style.dart';
import '../../../../widgets/app_bar/appbar_image.dart';
import '../../../../widgets/app_bar/appbar_title.dart';
import '../../../../widgets/app_bar/custom_app_bar.dart';
import 'package:barcode_widget/barcode_widget.dart';
import 'package:fluttertoast/fluttertoast.dart';
import '../../../../widgets/custom_button.dart';
import '../../../../widgets/custom_text_form_field.dart';
import 'package:flutter/material.dart';
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:intl/intl.dart';

import 'dart:math';
import '../../../../Reuseable/reusable_text_field.dart';
import '../../../../Reuseable/reusable_date_picker_field.dart';
import '../../../../Reuseable/reusable_date_time_picker_field.dart';
import '../../../../Reuseable/reusable_dropdown_field.dart';
import 'package:flutter/services.dart';
class Ad6UpdateEntityScreen extends StatefulWidget {
    final Map<String, dynamic> entity;


  Ad6UpdateEntityScreen({required this.entity});

  @override
  _Ad6UpdateEntityScreenState createState() => _Ad6UpdateEntityScreenState();
}

class _Ad6UpdateEntityScreenState extends State<Ad6UpdateEntityScreen> {
  final _formKey = GlobalKey<FormState>();

@override
  Widget build(BuildContext context) {
    return Consumer<Ad6ViewModelScreen>(
      builder: (context, viewModel, child) {
// Start with all fields, then remove upload fields (generic filter by keys)
        final Set<String> hiddenKeys = { 








 };
        final fields = Ad6Fields.getFields(context)
            .where((f) => !hiddenKeys.contains(f.fieldKey))
            .toList();        return EntityUpdateScreen(
          fields: fields,
          initialData: widget.entity,
          onSubmit: (data) => _handleSubmit(data),
          title: 'Ad6',
          isLoading: viewModel.isLoading,
          errorMessage:
              viewModel.errorMessage.isNotEmpty ? viewModel.errorMessage : null,
        );
      },
    );
  }

  Future<void> _handleSubmit(Map<String, dynamic> formData) async {
    final provider =
        Provider.of<Ad6ViewModelScreen>(context, listen: false);
    final success = await provider.updateEntity(widget.entity['id'], formData);

    if (success && mounted) {
      Navigator.pop(context);
    }
  }
}
