//
//  CommunityPostPurchaseDialog.swift
//  SodaLive
//
//  Created by klaus on 5/24/24.
//

import SwiftUI

struct CommunityPostPurchaseDialog: View {
    
    @Binding var isShowing: Bool
    
    let can: Int
    let confirmAction: () -> Void
    
    var body: some View {
        GeometryReader { geo in
            ZStack {
                Color.black
                    .opacity(0.5)
                    .frame(width: geo.size.width, height: geo.size.height)
                
                VStack(spacing: 0) {
                    Text("게시글 보기")
                        .font(.custom(Font.bold.rawValue, size: 18.3))
                        .foregroundColor(Color.graybb)
                        .padding(.top, 40)
                    
                    Text("게시글을\n확인하시겠습니까?")
                        .font(.custom(Font.medium.rawValue, size: 15))
                        .foregroundColor(Color.graybb)
                        .multilineTextAlignment(.center)
                        .padding(.top, 12)
                        .padding(.horizontal, 13.3)
                    
                    HStack(spacing: 13.3) {
                        Text("취소")
                            .font(.custom(Font.bold.rawValue, size: 15.3))
                            .foregroundColor(Color.button)
                            .padding(.vertical, 16)
                            .frame(width: (geo.size.width - 66.7) / 3)
                            .background(Color.bg)
                            .cornerRadius(8)
                            .overlay(
                                RoundedRectangle(cornerRadius: 8)
                                    .stroke(Color.button, lineWidth: 1)
                            )
                            .onTapGesture {
                                isShowing = false
                            }
                        
                        Text("\(can)캔으로 보기")
                            .font(.custom(Font.bold.rawValue, size: 15.3))
                            .foregroundColor(Color.white)
                        .padding(.vertical, 16)
                        .frame(width: (geo.size.width - 66.7) * 2 / 3)
                        .background(Color.button)
                        .cornerRadius(8)
                        .onTapGesture {
                            confirmAction()
                            isShowing = false
                        }
                    }
                    .padding(.top, 26.7)
                    .padding(.bottom, 16.7)
                }
                .frame(width: geo.size.width - 26.7, alignment: .center)
                .background(Color.gray22)
                .cornerRadius(10)
            }
        }
    }
}

#Preview {
    CommunityPostPurchaseDialog(
        isShowing: .constant(true),
        can: 10,
        confirmAction: {}
    )
}
