import 'package:didvan/config/theme_data.dart';
import 'package:didvan/models/new_statistic/exchange_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 Trade extends StatelessWidget {
  final ExChangeContent totalContent;
  const Trade({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(
                  "پایانی (%)",
                  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<Widget>((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: [
                                DidvanText(e.dp,
                                    style:
                                        Theme.of(context).textTheme.bodySmall,
                                    color: e.dtp == "high"
                                        ? 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(e.dl,
                                          style: Theme.of(context)
                                              .textTheme
                                              .bodySmall,
                                          color: e.dtl == "high"
                                              ? Theme.of(context)
                                                  .colorScheme
                                                  .success
                                              : Theme.of(context)
                                                  .colorScheme
                                                  .error),
                                      const DidvanText(" "),
                                      DidvanText(
                                        e.l.toString(),
                                        style: Theme.of(context)
                                            .textTheme
                                            .bodySmall,
                                      ),
                                    ],
                                  ),
                                )
                              ],
                            ),
                          )
                        ],
                      ))
                  .toList(),
            )
          ],
        ),
      ),
    );
  }
}
