import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../app.dart';

class SearchResultList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final SSearchController controller = Get.find();
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        // ignore: invalid_use_of_protected_member
        controller.state.searchResult.value.length > 0
            ? ListView.separated(
                shrinkWrap: true,
                physics: NeverScrollableScrollPhysics(),
                separatorBuilder: (context, index) => AppTheme.appColorDivider,
                // ignore: invalid_use_of_protected_member
                itemCount: controller.state.searchResult.value.length,
                itemBuilder: (_, index) {
                  final ProductModel productModel = controller.state.searchResult[index];
                  return InkWell(
                    onTap: () => controller.onProductTapped(productModel),
                    splashColor: Theme.of(context).splashColor,
                    child: Row(
                      children: [
                        Expanded(
                          flex: 2,
                          child: Text(
                            productModel.name,
                            maxLines: 3,
                            overflow: TextOverflow.ellipsis,
                          ),
                        ),
                        Spacer(),
                        // ignore: todo
                        // TODO: Change later
                        Text(productModel.formattedPrice),
                      ],
                    ),
                  );
                },
              )
            : Center(child: Text('No item found')),
        AppTheme.appColorDivider,
      ],
    );
  }
}
