import 'package:expansion_tile_card/expansion_tile_card.dart';
import 'package:flutter/material.dart';
import 'package:horizontal_list/horizontal_list.dart';

import '../../../../../packages/ambito_theme/ambito_theme.dart';
import '../../measure_detail_page.dart';

class GalleryCard extends StatelessWidget {
  const GalleryCard({
    super.key,
    required this.title,
    required this.widgets,
  });

  final String title;
  final List<Widget>? widgets;

  @override
  Widget build(BuildContext context) {
    if (widgets == null) {
      return const SizedBox();
    }

    final AmbitoTheme theme = getTheme(context);

    globalKeys.putIfAbsent(title, () => GlobalKey<ExpansionTileCardState>());

    return ExpansionTileCard(
      key: globalKeys[title],
      initiallyExpanded: true,
      contentPadding: const EdgeInsets.only(left: 16),
      elevation: 0,
      expandedTextColor: theme.currentColorScheme.outline,
      baseColor: theme.currentColorScheme.outline..withValues(alpha: .1),
      expandedColor: theme.currentColorScheme.outline..withValues(alpha: .1),
      title: Text(
        title,
        style: theme.currentThemeData.textTheme.labelMedium
            ?.copyWith(fontWeight: FontWeight.bold),
      ),
      children: [
        Align(
          alignment: Alignment.topLeft,
          child: Padding(
            padding: const EdgeInsets.only(left: 20, right: 20, bottom: 20),
            child: HorizontalListView(
              width: double.maxFinite, //Width of widget
              height: 150, //Height of widget
              list: widgets!, //List of widget
              iconNext:
                  const Icon(Icons.arrow_forward_ios), // Icon for button next
              iconPrevious:
                  const Icon(Icons.arrow_back_ios), // Icon for button previous
              curveAnimation:
                  Curves.fastLinearToSlowEaseIn, //Curve for animation
              durationAnimation:
                  const Duration(milliseconds: 300), //Duration of animation
              enableManualScroll: true, //Enable manual scroll
              onNextPressed: () {},
              onPreviousPressed: () {},
            ),
          ),
        ),
      ],
    );
  }
}
