//
//  WiredTransferFilterChip.swift
//  suixinkan
//

import SwiftUI

/// 有线传图筛选 Chip，对齐 Android FilterChipDropdown。
struct WiredTransferFilterChip: View {
    let label: String
    let options: [String]
    var enabled: Bool = true
    let onSelected: (String) -> Void

    var body: some View {
        Menu {
            if options.isEmpty {
                Button(label) {}
                    .disabled(true)
            } else {
                ForEach(options, id: \.self) { option in
                    Button(option) { onSelected(option) }
                }
            }
        } label: {
            HStack(spacing: 0) {
                Text(label)
                    .font(.system(size: 11))
                    .foregroundStyle(enabled && !options.isEmpty ? WiredTransferDesign.text666 : WiredTransferDesign.text999)
                    .lineLimit(1)
                    .frame(maxWidth: .infinity, alignment: .leading)
                if enabled, !options.isEmpty {
                    Image(systemName: "chevron.down")
                        .font(.system(size: 12, weight: .medium))
                        .foregroundStyle(WiredTransferDesign.text999)
                }
            }
            .padding(.horizontal, enabled && !options.isEmpty ? 8 : 8)
            .frame(height: WiredTransferDesign.filterChipHeight)
            .background(WiredTransferDesign.pageBackground)
            .clipShape(RoundedRectangle(cornerRadius: WiredTransferDesign.filterChipCornerRadius))
            .overlay {
                RoundedRectangle(cornerRadius: WiredTransferDesign.filterChipCornerRadius)
                    .stroke(WiredTransferDesign.borderLight, lineWidth: 1)
            }
        }
        .disabled(!enabled || options.isEmpty)
    }
}
