import 'package:didvan/config/theme_data.dart';
import 'package:didvan/constants/app_icons.dart';
import 'package:didvan/models/new_statistic/metal_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 MetalCard extends StatelessWidget {
  final MetalContent metalContent;
  const MetalCard({super.key, required this.metalContent});

  Color _diffColor(context) => metalContent.data.dt == 'high'
      ? Theme.of(context).colorScheme.success
      : Theme.of(context).colorScheme.error;

  @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.3),
                    borderRadius: const BorderRadius.all(Radius.circular(4))),
                child: Center(
                    child: DidvanText(
                  metalContent.title,
                  style: Theme.of(context).textTheme.bodyLarge,
                ))),
            const DidvanDivider(
              verticalPadding: 8,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                const DidvanText("قیمت پایانی امروز" " (ریال) "),
                DidvanText(metalContent.data.p)
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                const DidvanText("قیمت پایانی روز گذشته" " (ریال) "),
                DidvanText(metalContent.data.y)
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                const DidvanText("میزان تغییر" " (ریال) "),
                Row(
                  children: [
                    Icon(
                      metalContent.data.dt == 'high'
                          ? DidvanIcons.angle_up_regular
                          : DidvanIcons.angle_down_regular,
                      size: 14,
                      color: _diffColor(context),
                    ),
                    DidvanText(
                      metalContent.data.d,
                      color: _diffColor(context),
                    ),
                  ],
                )
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                const DidvanText("میزان تغییر" " (درصد) "),
                Row(
                  children: [
                    Icon(
                      metalContent.data.dt == 'high'
                          ? DidvanIcons.angle_up_regular
                          : DidvanIcons.angle_down_regular,
                      size: 14,
                      color: _diffColor(context),
                    ),
                    DidvanText(
                      "${metalContent.data.dp}%",
                      color: _diffColor(context),
                    ),
                  ],
                ),
              ],
            ),
            const DidvanDivider(
              verticalPadding: 8,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(
                  width: MediaQuery.of(context).size.width * 0.25,
                  child: Row(
                    children: [
                      DidvanText(
                        "خرید",
                        style: Theme.of(context).textTheme.bodyLarge,
                        color: Theme.of(context).colorScheme.success,
                      ),
                      DidvanText(
                        " / ",
                        style: Theme.of(context).textTheme.bodyLarge,
                      ),
                      DidvanText(
                        "فروش",
                        style: Theme.of(context).textTheme.bodyLarge,
                        color: Theme.of(context).colorScheme.error,
                      )
                    ],
                  ),
                ),
                const Expanded(child: VerticalDivider()),
                DidvanText(
                  "تعداد",
                  style: Theme.of(context).textTheme.bodyLarge,
                ),
                const Expanded(child: VerticalDivider()),
                SizedBox(
                  width: MediaQuery.of(context).size.width * 0.25,
                  child: DidvanText(
                    "حجم",
                    style: Theme.of(context).textTheme.bodyLarge,
                    textAlign: TextAlign.end,
                  ),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(
                  width: MediaQuery.of(context).size.width * 0.25,
                  child: DidvanText("حقیقی",
                      color: Theme.of(context).colorScheme.success),
                ),
                const Expanded(child: VerticalDivider()),
                DidvanText(
                  metalContent.data.bc1,
                ),
                const Expanded(child: VerticalDivider()),
                SizedBox(
                  width: MediaQuery.of(context).size.width * 0.25,
                  child: Directionality(
                    textDirection: TextDirection.ltr,
                    child: DidvanText(
                      metalContent.data.b1,
                      textAlign: TextAlign.start,
                    ),
                  ),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(
                  width: MediaQuery.of(context).size.width * 0.25,
                  child: DidvanText("حقیقی",
                      color: Theme.of(context).colorScheme.error),
                ),
                const Expanded(child: VerticalDivider()),
                DidvanText(
                  metalContent.data.sc1,
                ),
                const Expanded(child: VerticalDivider()),
                SizedBox(
                  width: MediaQuery.of(context).size.width * 0.25,
                  child: Directionality(
                    textDirection: TextDirection.ltr,
                    child: DidvanText(
                      metalContent.data.s1,
                      textAlign: TextAlign.start,
                    ),
                  ),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(
                  width: MediaQuery.of(context).size.width * 0.25,
                  child: DidvanText("حقوقی",
                      color: Theme.of(context).colorScheme.success),
                ),
                const Expanded(child: VerticalDivider()),
                DidvanText(
                  metalContent.data.bc2,
                ),
                const Expanded(child: VerticalDivider()),
                SizedBox(
                  width: MediaQuery.of(context).size.width * 0.25,
                  child: Directionality(
                    textDirection: TextDirection.ltr,
                    child: DidvanText(
                      metalContent.data.b2,
                      textAlign: TextAlign.start,
                    ),
                  ),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(
                  width: MediaQuery.of(context).size.width * 0.25,
                  child: DidvanText("حقوقی",
                      color: Theme.of(context).colorScheme.error),
                ),
                const Expanded(child: VerticalDivider()),
                DidvanText(
                  metalContent.data.sc2,
                ),
                const Expanded(child: VerticalDivider()),
                SizedBox(
                  width: MediaQuery.of(context).size.width * 0.25,
                  child: Directionality(
                    textDirection: TextDirection.ltr,
                    child: DidvanText(
                      metalContent.data.s2,
                      textAlign: TextAlign.start,
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
