import 'package:flutter/material.dart';
import 'package:unit2/model/profile/basic_information/adress.dart';
import 'package:unit2/theme-data.dart/box_shadow.dart';
import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart';

class AddressScreen extends StatelessWidget {
  final List<MainAdress> addresses;
  const AddressScreen({super.key, required this.addresses});

  @override
  Widget build(BuildContext context) {

    return  Scaffold(
      appBar: AppBar(title: const Text(adressScreenTitle),centerTitle:  true, backgroundColor: primary, actions: [AddLeading(onPressed: (){})],),
      body: addresses.isNotEmpty ? ListView.builder(
        padding: const EdgeInsets.symmetric(vertical: 8,horizontal: 10),
        itemCount: addresses.length,
        itemBuilder: (
        BuildContext context, int index){
          String? subdivision = addresses[index].details??'';
          String category = addresses[index].address!.category!.name!;
          String? barangay = addresses[index].address!.barangay != null?'${addresses[index].address!.barangay!.description!.toUpperCase()},':'';
          String cityMunicipality = addresses[index].address!.cityMunicipality!.description!;
          String province = addresses[index].address!.cityMunicipality!.province!.description!;
          String region = addresses[index].address!.cityMunicipality!.province!.region!.description!;
       return   Column(children: [
   
            Column(
              children: [
                Container(
                  width: screenWidth,
                 decoration: box1(),
                  padding: const EdgeInsets.fromLTRB(8,16,0,16),
                  child: Row(children: [
                    Expanded(child: Column(children: [
                      Row(children: [Text(subdivision,style: Theme.of(context).textTheme.titleMedium,), const SizedBox(width: 5,), 
                  
                      Text(category,style: Theme.of(context).textTheme.bodySmall,)],),
                      const Divider(),
                        const SizedBox(height: 5,),
                      Text("$barangay $cityMunicipality, $province, $region",style: Theme.of(context).textTheme.labelLarge,),
                    ],)),
                      IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert,color: Colors.grey,))
                  ]),
                ),
              ],
            ),
           const SizedBox(height: 5,),
          ],);
      }):const EmptyData(message: "You don't have address added. Please click + to add."),
    );
  }
}