//
//  OrderInfoRowView.swift
//  suixinkan
//

import SnapKit
import UIKit

/// 订单详情 key-value 行，对齐 Android InfoRow。
final class OrderInfoRowView: UIView {

    private let titleLabel = UILabel()
    private let valueLabel = UILabel()

    override init(frame: CGRect) {
        super.init(frame: frame)
        titleLabel.font = .app(.body)
        titleLabel.textColor = OrderTokens.label563
        valueLabel.font = .systemFont(ofSize: 14, weight: .medium)
        valueLabel.textColor = OrderTokens.valueBlack
        valueLabel.textAlignment = .right
        valueLabel.numberOfLines = 0

        addSubview(titleLabel)
        addSubview(valueLabel)
        titleLabel.snp.makeConstraints { make in
            make.leading.top.bottom.equalToSuperview()
            make.width.lessThanOrEqualToSuperview().multipliedBy(0.45)
        }
        valueLabel.snp.makeConstraints { make in
            make.trailing.top.bottom.equalToSuperview()
            make.leading.greaterThanOrEqualTo(titleLabel.snp.trailing).offset(AppSpacing.xs)
        }
    }

    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func apply(title: String, value: String, valueColor: UIColor = OrderTokens.valueBlack, usesPrimaryValue: Bool = false) {
        titleLabel.text = "\(title)："
        valueLabel.text = value
        valueLabel.textColor = usesPrimaryValue ? AppColor.primary : valueColor
    }
}
