import 'package:base_project/BuilderField/shared/fields/number_field.dart';
import 'package:base_project/BuilderField/shared/fields/password_field.dart';
import 'package:base_project/BuilderField/shared/fields/phone_field.dart';
import 'package:base_project/BuilderField/shared/fields/custom_text_field.dart';

import '../../../../BuilderField/shared/fields/base_field.dart';

import '../../../../BuilderField/shared/fields/date_field.dart';
import '../../../../BuilderField/shared/fields/datetime_field.dart';
import '../../../../BuilderField/shared/fields/email_field.dart';
import 'package:base_project/BuilderField/shared/fields/url_field.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../../../BuilderField/shared/fields/custom_text_field.dart' as shared_text;
import '../../../../BuilderField/shared/fields/one_to_one_relation_field.dart';
import '../../../../BuilderField/shared/fields/calculated_field.dart';
import '../../../../BuilderField/shared/fields/one_to_many_field.dart';
import '../../../../BuilderField/shared/fields/value_list_picker_field.dart';
import '../../../../BuilderField/shared/fields/captcha_field.dart';
import '../../../../BuilderField/shared/fields/switch_field.dart';
import '../../../../BuilderField/shared/fields/url_field.dart';

import '../../../../BuilderField/shared/fields/audio_upload_field.dart';
import '../../../../BuilderField/shared/fields/checkbox_field.dart';
import '../../../../BuilderField/shared/fields/file_upload_field.dart';
import '../../../../BuilderField/shared/fields/image_upload_field.dart';
import '../../../../BuilderField/shared/fields/radio_field.dart';
import '../../../../BuilderField/shared/fields/video_upload_field.dart';

import '../../../../BuilderField/shared/fields/autocomplete_dropdown_field.dart';
import '../../../../BuilderField/shared/fields/autocomplete_multiselect_field.dart';
import '../../../../BuilderField/shared/fields/one_to_one_relation_field.dart';
import '../../../../BuilderField/shared/fields/data_grid_field.dart';
import '../../../../BuilderField/shared/fields/dropdown_field.dart';
import '../../../../BuilderField/shared/fields/dynamic_dropdown_field.dart';
import '../../../../BuilderField/shared/fields/dynamic_multiselect_dropdown_field.dart';
import '../../../../BuilderField/shared/fields/static_multiselect_field.dart';
import '../../../../BuilderField/shared/fields/currency_field.dart';
import '../../../../BuilderField/shared/fields/field_group_field.dart';
import '../../../../BuilderField/shared/fields/qr_code_field.dart';
import '../../../../BuilderField/shared/fields/barcode_field.dart';
import '../../../../BuilderField/shared/fields/dependent_dropdown_field.dart';
 import '../Testbug_viewModel/Testbug_view_model_screen.dart';/// Field definitions for Testbug entity
/// This defines the structure and validation for Testbug forms
class TestbugFields {
  /// Get field definitions for Testbug entity
  static List<BaseField> getFields(BuildContext context) {
    final viewModel =
        Provider.of<TestbugViewModelScreen>(context, listen: false);
    return [
      // Basic Information
 CustomTextField(
        fieldKey: 'name',
        label: 'Name',
        hint: 'Enter Name',
        isRequired: true,
        maxLength: 50,
      ),

FileUploadField(
        fieldKey: 'fileupload_fields',
        label: 'Fileupload Fields',
 isRequired: false,
      ),

 FieldGroupField(
        fieldKey: 'field_groupnn',
        label: 'Field Groupnn',
        hint: 'Enter Field Groupnn',
        subFields: [

 
          GroupSubField(path: 'bar_code', label: 'bar_code', isRequired: true),
 

 
          GroupSubField(path: 'qr_code', label: 'qr_code', isRequired: true),
 

          
        ],
      ),

OneToOneRelationField(
        fieldKey: 'child',
        label: 'child',
        hint: 'child details',
        relationSchema: {
          'title': 'child',
          'box': true,
          'fields': [

 
            {
              'type': 'text',
              'label': 'Namek',
              'hint': 'Enter Namek',
              'path': 'child.namek',
            },

            
	
          ],
        },
      ),


// 3) Value list picker â fill fields from selection (provide your loader)
      ValueListPickerField(
        fieldKey: 'value_list_fieldcc',
        label: 'Value List Fieldcc',
       optionsLoader: () async {
           try {
 await viewModel.getEntities();
            final response = viewModel.testbugList;
            return response;
          } catch (e) {
            // Return empty list if API fails
            return <Map<String, dynamic>>[];
          }
        },
        fillMappings: const {
	
 
          'name': 'name',
 

         
        },
      ),

  DataGridField(
        fieldKey: 'datagrid_fieldv',
        label: 'datagrid Fieldv',
        dataLoader: () => viewModel.getdatagrid_fieldvGrid(),
      ),

 DynamicDropdownField(
        fieldKey: 'select_dyanamic',
        label: 'Select select dyanamic',
         hint: 'Search and select',
        optionsLoader: () => viewModel.getselect_dyanamic(),

 
        valueKey: 'id',
        displayKey: 'name',
 

      ),


 DynamicMultiSelectDropdownField(
        fieldKey: 'select_dynamic_mul',
        label: 'select dynamic mul',
        hint: 'Type to search and press enter',
        optionsLoader: () async {
          final list = await viewModel.getselect_dynamic_mul();
          return list

 
              .map((e) => e['name']?.toString() ?? '')
              .where((e) => e.isNotEmpty)
              .toList();
 

        },
      ),




  AutocompleteDropdownField(
        fieldKey: 'select_autocomp',
        label: 'select autocomp',
        hint: 'Select select autocomp',
        optionsLoader: () async => await viewModel.getselect_autocomp(),

 
        valueKey: 'id',
        displayKey: 'name',
 

        isRequired: false,
      ),



  AutocompleteMultiSelectField(
        fieldKey: 'select_autcomp_mul',
        label: 'select autcomp mul',
        hint: 'Select select autcomp mul',
   isRequired: false,
       optionsLoader: () async {
          final data = await viewModel.getselect_autcomp_mul();

 
          return data
              .map((e) => e['id'])
              .where((e) => e != null)
              .map<String>((e) => e.toString())
              .toList();
 

        },
      ),

    ];
  }
}
