import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:pharmacy_mobile/tables/ref_medicines.dart';
import 'package:pharmacy_mobile/tables/storage.dart';
import 'package:pharmacy_mobile/widgets/button_widget.dart';
import 'package:pharmacy_mobile/widgets/input_widget.dart';
import 'package:pharmacy_mobile/widgets/item_card_widget.dart';
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
import 'package:pharmacy_mobile/widgets/text_widget.dart';
import 'package:pharmacy_mobile/widgets/title_widget.dart';

class CustomerSearchPage extends StatefulWidget {
  // final NotchBottomBarController? controller;
  // final
  const CustomerSearchPage({super.key});

  @override
  State<CustomerSearchPage> createState() => _CustomerSearchPageState();
}

class _CustomerSearchPageState extends State<CustomerSearchPage> {
  final _searchController = TextEditingController();
  final _storage = Storage();
  // final _refMedicines = RefMedicines();
  late String imageUrl = '';
  // List<String> imageUrl = [];

  void getURL() async {
    final image = await _storage.getPublicURL('ref_medicines_images', 'cb6eafdb-d86f-460a-9571-44446570d4cb.webp');
    setState(() {
      imageUrl = image;
    });

    // final meds = await _refMedicines.getList2();
    // log(meds.toString());
  }

  // void getURLs() async {
  //   try {
  //     for (int i = 1; i <= 4; i++) {
  //       final image = await _storage.getPublicURL(
  //         context,
  //         'ref_medicines_images',
  //         'ca3e2949-4964-4d25-a274-2a18608b7bdb.webp', // Replace with your actual image path
  //       );
  //       log(image);
  //       setState(() {
  //         imageUrl.add(image);
  //       });
  //     }
  //   } catch (e, stackTrace) {
  //     log('Error getting URLs: $e', stackTrace: stackTrace);
  //   }
  // }

  void _filterList() {}

  @override
  void initState() {
    getURL();
    super.initState();
  }

  @override
  void dispose() {
    _searchController.dispose();
    imageUrl = '';
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    const double imageSize = 180;

    return Scaffold(
        body: PageBackgroundWidget(
            // height: MediaQuery.of(context).size.height * 2,
            child: Column(
      children: [
        Column(
          children: [
            const Gap(96),
            const TitleWidget(
              firstTextSize: 14,
              secondTextSize: 24,
              logoSize: 90,
            ),
            const Gap(32),
            Container(
              padding: EdgeInsets.only(left: 64, right: 64),
              child: Column(
                children: [
                  InputWidget(
                    label: '',
                    controller: _searchController,
                    placeholder: 'Search for medicine',
                  ),
                  // const Gap(8),
                  // ButtonWidget(
                  //   text: 'Search',
                  //   onPressed: _filterList,
                  //   width: 160,
                  // )
                ],
              ),
            ),
            const Gap(32),
            // Center(
            //   child: imageUrl.isNotEmpty
            //       ? ClipRRect(
            //           borderRadius: BorderRadius.circular(12), // Add your desired border radius here
            //           child: Image.network(imageUrl,
            //               fit: BoxFit.cover,
            //               width: 250,
            //               height: 250,
            //               cacheWidth: (250 * MediaQuery.of(context).devicePixelRatio).round()))
            //       : const CircularProgressIndicator(
            //           color: Colors.white,
            //           strokeWidth: 4,
            //           padding: EdgeInsets.all(8),
            //         ),
            // )
            Column(
              children: [
                Padding(
                  padding: const EdgeInsets.fromLTRB(0, 8, 0, 8),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      ItemCardWidget(
                        imageUrl: imageUrl,
                        text: 'sample',
                        price: 500,
                        quantity: 15,
                      ),
                      ItemCardWidget(
                        imageUrl: imageUrl,
                        text: 'sample',
                        price: 20,
                        quantity: 85,
                      ),
                    ],
                  ),
                )
              ],
            ),
            Column(
              children: [
                Padding(
                  padding: const EdgeInsets.fromLTRB(0, 8, 0, 8),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      ItemCardWidget(
                        imageUrl: imageUrl,
                        text: 'sample',
                        price: 500,
                        quantity: 15,
                      ),
                      ItemCardWidget(
                        imageUrl: imageUrl,
                        text: 'sample',
                        price: 20,
                        quantity: 85,
                      ),
                    ],
                  ),
                )
              ],
            )
          ],
        )
      ],
    )));
  }
}
