import SwiftUI

// MARK: - 输入标题组件
struct InputTitleView: View {
    let title: String
    let isRequired: Bool
    let icon: String?
    
    init(_ title: String, isRequired: Bool = false, icon: String? = nil) {
        self.title = title
        self.isRequired = isRequired
        self.icon = icon
    }
    
    var body: some View {
        HStack(spacing: 8) {
            if let icon = icon {
                Image(systemName: icon)
                    .font(.subheadline)
                    .foregroundColor(.blue)
            }
            
            Text(title)
                .font(.subheadline)
                .foregroundColor(.primary)
            
            if isRequired {
                Text("*")
                    .foregroundColor(.red)
                    .font(.subheadline)
            }
            
            Spacer()
        }
    }
}

// MARK: - 预定义的标题样式
extension InputTitleView {
    static func required(_ title: String, icon: String? = nil) -> InputTitleView {
        InputTitleView(title, isRequired: true, icon: icon)
    }
    
    static func optional(_ title: String, icon: String? = nil) -> InputTitleView {
        InputTitleView(title, isRequired: false, icon: icon)
    }
}

#Preview {
    VStack(spacing: 16) {
        InputTitleView.required("必填字段", icon: "star.fill")
        InputTitleView.optional("可选字段", icon: "circle")
        InputTitleView("普通标题")
        InputTitleView.required("邮箱地址", icon: "envelope")
        InputTitleView.required("密码", icon: "lock")
    }
    .padding()
} 