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

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

class SearchHistoryListWidget extends StatelessWidget {
  const SearchHistoryListWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final SSearchController controller = Get.find();
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ListView.separated(
          shrinkWrap: true,
          physics: NeverScrollableScrollPhysics(),
          separatorBuilder: (context, index) => AppTheme.appColorDivider,
          // ignore: invalid_use_of_protected_member
          itemCount: controller.state.searchHistoryList.value.length,
          itemBuilder: (_, index) {
            final SearchHistory searchHistory = controller.state.searchHistoryList[index];
            return Row(
              children: [
                Text(searchHistory.id.toString() + ': ' + searchHistory.keyword),
                Spacer(),
                Text(searchHistory.field ?? ''),
              ],
            );
          },
        ),
        AppTheme.appColorDivider,
        TextButton(
          onPressed: controller.resetSearchHistory,
          style: TextButton.styleFrom(
            foregroundColor: HexColor('#30A8FF'), padding: EdgeInsets.zero,
            minimumSize: Size(50, 30),
            alignment: Alignment.centerLeft,
          ),
          child: Text('Clear history'),
        ),
      ],
    );
  }
}
