import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:llswidget/llswidget.dart';
import 'package:flutter/cupertino.dart';

Future<void> main() async {
  final childWidget = Container(
    width: 100,
    height: 100,
  );

  const color = Colors.white;
  const elevation = 2.0;
  const borderOnForeground = false;
  const padding = EdgeInsets.symmetric(horizontal: 12, vertical: 8);
  const margin = EdgeInsets.all(1);
  const title = LLSListTile(
    titleText: 'Card Title',
    icon: Icon(Icons.favorite_border),
  );
  const content = Text('Hello');
  final borderRadius = BorderRadius.circular(10);
  const border = Border(top: BorderSide(color: Colors.black));

  testWidgets('LLS Card can be created.', (tester) async {
    final LLSCard card = LLSCard(
      color: color,
      elevation: elevation,
      borderOnForeground: borderOnForeground,
      padding: padding,
      margin: margin,
      title: title,
      content: childWidget,
      imageOverlay: const NetworkImage(
          'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
    );

    final TestApp app = TestApp(card);

    await tester.pumpWidget(app);

    await tester.pumpWidget(Container(child: childWidget));
    expect(find.byWidget(childWidget), findsOneWidget);
    expect(app.card.color, color);
    expect(app.card.elevation, elevation);
    expect(app.card.borderOnForeground, borderOnForeground);
    expect(app.card.padding, padding);
    expect(app.card.margin, margin);
    expect(app.card.title, title);
    expect(app.card.content, childWidget);
  });

//   testWidgets('LLS Card with color gradient.', (tester) async {
//     const gradient = LinearGradient(
//         begin: Alignment.topLeft,
//         end: Alignment.bottomRight,
//         colors: [Colors.red, Colors.pink]);
//     final LLSCard card = LLSCard(
//       gradient: gradient,
//       elevation: elevation,
//       borderOnForeground: borderOnForeground,
//       padding: padding,
//       margin: margin,
//       title: title,
//       image: Image.network(
//           'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
//       imageOverlay: const NetworkImage(
//           'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
//     );

//     final TestApp app = TestApp(card);

//     await tester.pumpWidget(app);

//     await tester.pumpWidget(Container(child: childWidget));
//     expect(find.byWidget(childWidget), findsOneWidget);
//     expect(app.card.gradient, gradient);
//     expect(app.card.elevation, elevation);
//     expect(app.card.borderOnForeground, borderOnForeground);
//     expect(app.card.padding, padding);
//     expect(app.card.margin, margin);
//     expect(app.card.title, title);
//   });

//   testWidgets('LLS Card with clip behaviour.', (tester) async {
//     final bgImage = Image.network(
//       'https://images.unsplash.com/photo-1547721064-da6cfb341d50',
//     );
//     const clip = Clip.none;

//     final LLSCard card = LLSCard(
//       image: bgImage,
//       title: title,
//       clipBehavior: clip,
//       imageOverlay: const NetworkImage(
//           'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
//     );

//     final TestApp app = TestApp(card);

//     expect(app.card.image, bgImage);
//     expect(app.card.title, title);
//     expect(app.card.clipBehavior, clip);
//   });

//   testWidgets('LLS Card with background image.', (tester) async {
//     final bgImage = Image.network(
//       'https://images.unsplash.com/photo-1547721064-da6cfb341d50',
//     );
//     const boxFit = BoxFit.cover;

//     final LLSCard card = LLSCard(
//       image: bgImage,
//       title: title,
//       boxFit: boxFit,
//       imageOverlay: const NetworkImage(
//           'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
//     );

//     final TestApp app = TestApp(card);

//     expect(app.card.image, bgImage);
//     expect(app.card.title, title);
//     expect(app.card.boxFit, boxFit);
//   });

//   testWidgets('LLS Card with background image & image overlay.', (tester) async {
//     final bgImage = Image.network(
//       'https://images.unsplash.com/photo-1547721064-da6cfb341d50',
//     );
//     const boxFit = BoxFit.cover;
//     const imageOverlay = NetworkImage(
//         'https://cdn.pixabay.com/photo/2016/11/22/07/09/spruce-1848543__340.jpg');

//     final LLSCard card = LLSCard(
//       image: bgImage,
//       title: title,
//       boxFit: boxFit,
//       imageOverlay: imageOverlay,
//     );

//     final TestApp app = TestApp(card);

//     expect(app.card.image, bgImage);
//     expect(app.card.title, title);
//     expect(app.card.boxFit, boxFit);
//     expect(app.card.imageOverlay, imageOverlay);
//   });

//   testWidgets('LLS Card with semantic container.', (tester) async {
//     const isSemanticContainer = false;

//     final LLSCard card = LLSCard(
//       semanticContainer: isSemanticContainer,
//       elevation: elevation,
//       borderOnForeground: borderOnForeground,
//       title: title,
//       image: Image.network(
//           'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
//       imageOverlay: const NetworkImage(
//           'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
//     );

//     final TestApp app = TestApp(card);

//     await tester.pumpWidget(app);

//     await tester.pumpWidget(Container(child: childWidget));
//     expect(find.byWidget(childWidget), findsOneWidget);
//     expect(app.card.semanticContainer, isSemanticContainer);
//     expect(app.card.elevation, elevation);
//     expect(app.card.borderOnForeground, borderOnForeground);
//     expect(app.card.title, title);
//   });

//   testWidgets('LLS Card with title position.', (tester) async {
//     final bgImage = Image.network(
//       'https://images.unsplash.com/photo-1547721064-da6cfb341d50',
//     );
//     const titlePosition = LLSPosition.end;

//     final LLSCard card = LLSCard(
//       image: bgImage,
//       title: title,
//       titlePosition: titlePosition,
//       imageOverlay: const NetworkImage(
//           'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
//     );

//     final TestApp app = TestApp(card);

//     expect(app.card.image, bgImage);
//     expect(app.card.title, title);
//     expect(app.card.titlePosition, titlePosition);
//   });

//   testWidgets('LLS Card with border & border radius.', (tester) async {
//     final bgImage = Image.network(
//       'https://images.unsplash.com/photo-1547721064-da6cfb341d50',
//     );
//     final LLSCard card = LLSCard(
//       title: title,
//       border: border,
//       borderRadius: borderRadius,
//       image: bgImage,
//       content: content,
//       imageOverlay: const NetworkImage(
//           'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
//     );

//     final TestApp app = TestApp(card);

//     await tester.pumpWidget(Container(child: childWidget));
//     expect(find.byWidget(childWidget), findsOneWidget);
//     expect(app.card.title, title);
//     expect(app.card.border, border);
//     expect(app.card.borderRadius, borderRadius);
//     expect(app.card.content, content);
//     expect(app.card.image, bgImage);
//   });

//   testWidgets('LLS Card with custom button bar.', (tester) async {
//     final bgImage = Image.network(
//       'https://images.unsplash.com/photo-1547721064-da6cfb341d50',
//     );
//     const customButtonBar = LLSButtonBar(
//       children: <Widget>[
//         LLSButton(
//           onPressed: null,
//           child: Text('Read More'),
//           icon: Icon(Icons.keyboard_arrow_right),
//           type: LLSButtonType.transparent,
//         ),
//       ],
//     );
//     final LLSCard card = LLSCard(
//       color: color,
//       elevation: elevation,
//       buttonBar: customButtonBar,
//       title: title,
//       image: bgImage,
//       imageOverlay: const NetworkImage(
//           'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
//     );

//     final TestApp app = TestApp(card);

//     await tester.pumpWidget(Container(child: childWidget));
//     expect(find.byWidget(childWidget), findsOneWidget);
//     expect(app.card.color, color);
//     expect(app.card.elevation, elevation);
//     expect(app.card.buttonBar, customButtonBar);
//     expect(app.card.image, bgImage);
//   });

//   testWidgets('LLS Card with custom title.', (tester) async {
//     const customTitle = LLSListTile(
//       titleText: 'Card Title',
//       icon: Icon(Icons.favorite_border),
//     );
//     final LLSCard card = LLSCard(
//       color: color,
//       title: customTitle,
//       image: Image.network(
//           'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
//       imageOverlay: const NetworkImage(
//           'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
//     );

//     final TestApp app = TestApp(card);

//     await tester.pumpWidget(app);

//     await tester.pumpWidget(Container(child: childWidget));
//     expect(find.byWidget(childWidget), findsOneWidget);
//     expect(app.card.color, color);
//     expect(app.card.title, customTitle);
//   });

//   testWidgets('LLS Card with full background image & button bar.',
//       (tester) async {
//     const imageOverlay = NetworkImage(
//         'https://cdn.pixabay.com/photo/2016/11/22/07/09/spruce-1848543__340.jpg');
//     final colorFilter =
//         ColorFilter.mode(Colors.black.withOpacity(0.67), BlendMode.darken);
//     const customTitle = LLSListTile(
//       titleText: 'Card Title',
//       subTitleText: 'Sub title',
//     );
//     final LLSCard card = LLSCard(
//       color: color,
//       title: customTitle,
//       imageOverlay: imageOverlay,
//       colorFilter: colorFilter,
//       image: Image.network(
//           'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'),
//     );

//     final TestApp app = TestApp(card);

//     await tester.pumpWidget(Container(child: childWidget));
//     expect(find.byWidget(childWidget), findsOneWidget);
//     expect(app.card.color, color);
//     expect(app.card.title, customTitle);
//     expect(app.card.imageOverlay, imageOverlay);
//     expect(app.card.colorFilter, colorFilter);
//   });
}

class TestApp extends StatefulWidget {
  const TestApp(this.card);

  final LLSCard card;

  @override
  _TestAppState createState() => _TestAppState();
}

class _TestAppState extends State<TestApp> {
  bool fav = false;

  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Scaffold(
          body: Column(
            children: [
              widget.card,
            ],
          ),
        ),
      );
}