import 'package:flutter/material.dart';
import 'package:superport/models/company_model.dart';
import 'package:superport/models/address_model.dart';

/// 회사/지점 정보를 1행(1열)로 보여주는 재활용 위젯
class CompanyInfoCard extends StatelessWidget {
  final String title; // 본사/지점 구분
  final String name;
  final List<CompanyType> companyTypes;
  final Address address;
  final String? contactName;
  final String? contactPosition;
  final String? contactPhone;
  final String? contactEmail;

  const CompanyInfoCard({
    super.key,
    required this.title,
    required this.name,
    required this.companyTypes,
    required this.address,
    this.contactName,
    this.contactPosition,
    this.contactPhone,
    this.contactEmail,
  });

  @override
  Widget build(BuildContext context) {
    // 각 데이터가 없으면 빈 문자열로 표기
    final String zipCode = address.zipCode.isNotEmpty ? address.zipCode : '';
    final String displayName = name.isNotEmpty ? name : '';
    final String displayContactName =
        contactName != null && contactName!.isNotEmpty ? contactName! : '';
    final String displayContactPosition =
        contactPosition != null && contactPosition!.isNotEmpty
            ? contactPosition!
            : '';
    final String displayContactPhone =
        contactPhone != null && contactPhone!.isNotEmpty ? contactPhone! : '';
    final String displayContactEmail =
        contactEmail != null && contactEmail!.isNotEmpty ? contactEmail! : '';

    return Card(
      color: Colors.grey.shade50,
      child: Padding(
        padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 12),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 본사/지점 구분만 상단에 표기 (텍스트 크기 14로 축소)
            Text(
              title,
              style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
            ),
            const SizedBox(height: 2), // 간격도 절반으로 축소
            // 1행(1열)로 데이터만 표기
            SingleChildScrollView(
              scrollDirection: Axis.horizontal,
              child: Row(
                children: [
                  Text(displayName, style: const TextStyle(fontSize: 13)),
                  const SizedBox(width: 12),
                  Text(zipCode, style: const TextStyle(fontSize: 13)),
                  const SizedBox(width: 12),
                  Text(
                    displayContactName,
                    style: const TextStyle(fontSize: 13),
                  ),
                  const SizedBox(width: 12),
                  Text(
                    displayContactPosition,
                    style: const TextStyle(fontSize: 13),
                  ),
                  const SizedBox(width: 12),
                  Text(
                    displayContactPhone,
                    style: const TextStyle(fontSize: 13),
                  ),
                  const SizedBox(width: 12),
                  Text(
                    displayContactEmail,
                    style: const TextStyle(fontSize: 13),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
