import 'package:flutter/material.dart';

import '../../core/constants/market_list_layout.dart';

/// 行情列表数据行：左侧名称区 | 固定宽最新价 | 间距 | 固定宽涨跌幅。
class MarketListDataRow extends StatelessWidget {
  const MarketListDataRow({
    super.key,
    this.leading,
    this.leadingGap = kMarketListLeadingToNameGap,
    required this.name,
    required this.price,
    required this.change,
  });

  /// 图标等；为 null 时不占 leading 间距（表头无图标场景）。
  final Widget? leading;

  /// [leading] 与 [name] 之间的间距；leading 已自带间距时可传 0。
  final double leadingGap;

  final Widget name;
  final Widget price;
  final Widget change;

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Expanded(
          child: Row(
            children: [
              if (leading != null) ...[
                leading!,
                if (leadingGap > 0) SizedBox(width: leadingGap),
              ],
              Expanded(child: name),
            ],
          ),
        ),
        SizedBox(
          width: kMarketListPriceColumnWidth,
          child: FittedBox(
            fit: BoxFit.scaleDown,
            alignment: Alignment.centerRight,
            child: SizedBox(
              width: kMarketListPriceColumnWidth,
              child: price,
            ),
          ),
        ),
        const SizedBox(width: kMarketListPriceToBadgeGap),
        SizedBox(
          width: kMarketListChangeBadgeWidth,
          child: FittedBox(
            fit: BoxFit.scaleDown,
            alignment: Alignment.center,
            child: SizedBox(
              width: kMarketListChangeBadgeWidth,
              child: change,
            ),
          ),
        ),
      ],
    );
  }
}

/// 行情列表表头，列宽与 [MarketListDataRow] 一致。
class MarketListHeaderRow extends StatelessWidget {
  const MarketListHeaderRow({
    super.key,
    this.leading,
    this.leadingGap = kMarketListLeadingToNameGap,
    required this.name,
    required this.price,
    required this.change,
  });

  final Widget? leading;
  final double leadingGap;
  final Widget name;
  final Widget price;
  final Widget change;

  @override
  Widget build(BuildContext context) {
    return MarketListDataRow(
      leading: leading,
      leadingGap: leadingGap,
      name: name,
      price: price,
      change: change,
    );
  }
}
