//
//  SpecifyUploadBottomSheet.swift
//  suixinkan
//

import SwiftUI

/// 指定上传 Bottom Sheet，对齐 Android SpecifyUploadBottomSheet。
struct SpecifyUploadBottomSheet: View {
    @Binding var isPresented: Bool
    let onConfirm: (String) -> Void

    @State private var selectedOption = WiredCameraTransferViewModel.specifyUploadAllPending

    private let options = [
        WiredCameraTransferViewModel.specifyUploadAllPending,
        WiredCameraTransferViewModel.specifyUploadTodayCaptured
    ]

    var body: some View {
        NavigationStack {
            VStack(spacing: 0) {
                VStack(spacing: 12) {
                    ForEach(options, id: \.self) { option in
                        optionRow(option)
                    }
                }
                .padding(.horizontal, 16)
                .padding(.top, 12)

                Spacer(minLength: 20)

                HStack(spacing: 12) {
                    Button("取消") { isPresented = false }
                        .font(.system(size: 16, weight: .medium))
                        .foregroundStyle(AppDesign.primary)
                        .frame(maxWidth: .infinity)
                        .frame(height: 48)
                        .background(Color.white)
                        .overlay {
                            RoundedRectangle(cornerRadius: 10)
                                .stroke(AppDesign.primary, lineWidth: 1)
                        }

                    Button("确认上传") {
                        onConfirm(selectedOption)
                    }
                    .font(.system(size: 16, weight: .medium))
                    .foregroundStyle(.white)
                    .frame(maxWidth: .infinity)
                    .frame(height: 48)
                    .background(AppDesign.primary)
                    .clipShape(RoundedRectangle(cornerRadius: 10))
                }
                .padding(.horizontal, 16)
                .padding(.vertical, 12)
            }
            .background(WiredTransferDesign.pageBackground)
            .navigationTitle("指定上传")
            .navigationBarTitleDisplayMode(.inline)
        }
        .onAppear {
            selectedOption = options.first ?? WiredCameraTransferViewModel.specifyUploadAllPending
        }
    }

    private func optionRow(_ option: String) -> some View {
        Button {
            selectedOption = option
        } label: {
            HStack {
                Text(option)
                    .font(.system(size: 15))
                    .foregroundStyle(WiredTransferDesign.text333)
                    .frame(maxWidth: .infinity, alignment: .leading)
                Image(systemName: selectedOption == option ? "largecircle.fill.circle" : "circle")
                    .foregroundStyle(selectedOption == option ? WiredTransferDesign.text333 : WiredTransferDesign.borderLight)
            }
            .padding(.horizontal, 14)
            .padding(.vertical, 8)
            .background(Color.white)
            .clipShape(RoundedRectangle(cornerRadius: 10))
            .overlay {
                RoundedRectangle(cornerRadius: 10)
                    .stroke(WiredTransferDesign.borderLight, lineWidth: 1)
            }
        }
        .buttonStyle(.plain)
    }
}
