import 'package:didvan/config/theme_data.dart';
import 'package:didvan/models/new_statistic/total_model.dart';
import 'package:didvan/views/widgets/didvan/card.dart';
import 'package:didvan/views/widgets/didvan/divider.dart';
import 'package:didvan/views/widgets/didvan/text.dart';
import 'package:flutter/material.dart';

class TotalType4Card extends StatelessWidget {
  final TotalContent totalContent;
  const TotalType4Card({super.key, required this.totalContent});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: DidvanCard(
        padding: const EdgeInsets.all(8),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              decoration: BoxDecoration(
                  color: Colors.grey.withValues(alpha: 0.4),
                  borderRadius: const BorderRadius.all(Radius.circular(4))),
              child: Center(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    DidvanText(
                      totalContent.title,
                      style: Theme.of(context).textTheme.bodyLarge,
                      textAlign: TextAlign.center,
                    ),
                  ],
                ),
              ),
            ),
            const DidvanDivider(
              verticalPadding: 8,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(
                  width: MediaQuery.of(context).size.width * 0.3,
                  child: DidvanText(
                    "نماد",
                    style: Theme.of(context).textTheme.bodyLarge,
                  ),
                ),
                DidvanText(
                  [34, 35].contains(totalContent.id)
                      ? "قدرت خریداران"
                      : totalContent.id == 50
                          ? "ضریب حجم"
                          : "پایانی (%)",
                  style: Theme.of(context).textTheme.bodyLarge,
                ),
                SizedBox(
                  width: MediaQuery.of(context).size.width * 0.3,
                  child: DidvanText(
                    "آخرین (%)",
                    style: Theme.of(context).textTheme.bodyLarge,
                    textAlign: TextAlign.end,
                  ),
                ),
              ],
            ),
            Column(
              children: totalContent.data
                  .map((e) => Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          SizedBox(
                            width: MediaQuery.of(context).size.width * 0.3,
                            child: DidvanText(
                              e.name.toString(),
                              overflow: TextOverflow.fade,
                              style: Theme.of(context).textTheme.bodySmall,
                            ),
                          ),
                          Directionality(
                            textDirection: TextDirection.ltr,
                            child: Row(
                              children: [34, 35, 50].contains(totalContent.id)
                                  ? [
                                      DidvanText(
                                        e.f,
                                        style: Theme.of(context)
                                            .textTheme
                                            .bodySmall,
                                      )
                                    ]
                                  : [
                                      DidvanText(
                                          "(${(double.parse(e.dp)).abs()})",
                                          style: Theme.of(context)
                                              .textTheme
                                              .bodySmall,
                                          color: double.parse(e.dp) > 0
                                              ? Theme.of(context)
                                                  .colorScheme
                                                  .success
                                              : Theme.of(context)
                                                  .colorScheme
                                                  .error),
                                      const DidvanText(" "),
                                      DidvanText(
                                        e.p.toString(),
                                        style: Theme.of(context)
                                            .textTheme
                                            .bodySmall,
                                      ),
                                    ],
                            ),
                          ),
                          SizedBox(
                            width: MediaQuery.of(context).size.width * 0.3,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                Directionality(
                                  textDirection: TextDirection.ltr,
                                  child: Row(
                                    children: [
                                      DidvanText(
                                          "(${double.parse(e.dl).abs()})",
                                          style: Theme.of(context)
                                              .textTheme
                                              .bodySmall,
                                          color: double.parse(e.dl) > 0
                                              ? Theme.of(context)
                                                  .colorScheme
                                                  .success
                                              : Theme.of(context)
                                                  .colorScheme
                                                  .error),
                                      const DidvanText(" "),
                                      DidvanText(
                                        e.l,
                                        style: Theme.of(context)
                                            .textTheme
                                            .bodySmall,
                                      ),
                                    ],
                                  ),
                                ),
                              ],
                            ),
                          )
                        ],
                      ))
                  .toList(),
            )
          ],
        ),
      ),
    );
  }
}
