import 'package:flutter/material.dart';
import 'package:superport/models/address_model.dart';
import 'package:superport/screens/common/custom_widgets.dart';
import 'package:superport/screens/common/widgets/address_input.dart';
import 'package:superport/screens/company/widgets/company_name_autocomplete.dart';
import 'package:superport/screens/common/widgets/remark_input.dart';

class CompanyFormHeader extends StatelessWidget {
  final TextEditingController nameController;
  final FocusNode nameFocusNode;
  final List<String> companyNames;
  final List<String> filteredCompanyNames;
  final bool showCompanyNameDropdown;
  final Function(String) onCompanyNameSelected;
  final Function() onShowMapPressed;
  final ValueChanged<String?> onNameSaved;
  final ValueChanged<Address> onAddressChanged;
  final Address initialAddress;
  final String nameLabel;
  final String nameHint;
  final TextEditingController remarkController;

  const CompanyFormHeader({
    super.key,
    required this.nameController,
    required this.nameFocusNode,
    required this.companyNames,
    required this.filteredCompanyNames,
    required this.showCompanyNameDropdown,
    required this.onCompanyNameSelected,
    required this.onShowMapPressed,
    required this.onNameSaved,
    required this.onAddressChanged,
    this.initialAddress = const Address(),
    required this.nameLabel,
    required this.nameHint,
    required this.remarkController,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        // 회사명/지점명
        FormFieldWrapper(
          label: nameLabel,
          isRequired: true,
          child: CompanyNameAutocomplete(
            nameController: nameController,
            nameFocusNode: nameFocusNode,
            companyNames: companyNames,
            filteredCompanyNames: filteredCompanyNames,
            showCompanyNameDropdown: showCompanyNameDropdown,
            onCompanyNameSelected: onCompanyNameSelected,
            onNameSaved: onNameSaved,
            label: nameLabel,
            hint: nameHint,
          ),
        ),

        // 주소 입력 위젯 (SRP에 따라 별도 컴포넌트로 분리)
        AddressInput(
          initialZipCode: initialAddress.zipCode,
          initialRegion: initialAddress.region,
          initialDetailAddress: initialAddress.detailAddress,
          isRequired: false,
          onAddressChanged: (zipCode, region, detailAddress) {
            final address = Address(
              zipCode: zipCode,
              region: region,
              detailAddress: detailAddress,
            );
            onAddressChanged(address);
          },
        ),
        const SizedBox(height: 12),
        // 비고 입력란
        RemarkInput(controller: remarkController),
      ],
    );
  }
}
