//
//  ContentOrderDialogView.swift
//  SodaLive
//
//  Created by klaus on 2023/08/13.
//

import SwiftUI

struct ContentOrderDialogView: View {
    
    @Binding var isShowing: Bool
    
    let price: Int
    let isOnlyRental: Bool
    let onTapPurchase: (OrderType) -> Void
    
    var body: some View {
        ZStack {
            Color.black
                .opacity(0.7)
                .ignoresSafeArea()
                .onTapGesture { isShowing = false }
            
            VStack(spacing: 0) {
                Spacer()
                
                VStack(spacing: 26.7) {
                    HStack(spacing: 0) {
                        VStack(alignment: .leading, spacing: 5.3) {
                            Text("대여")
                                .font(.custom(Font.bold.rawValue, size: 13.3))
                                .foregroundColor(.white)
                            
                            Text("(이용기간 15일)")
                                .font(.custom(Font.light.rawValue, size: 12))
                                .foregroundColor(.white)
                        }
                        
                        Spacer()
                        
                        HStack(spacing: 8) {
                            Image("ic_can")
                                .resizable()
                                .frame(width: 16.7, height: 16.7)
                            
                            Text(isOnlyRental ? "\(price)" : "\(Int(ceil(Double(price) * 0.6)))")
                                .font(.custom(Font.bold.rawValue, size: 13.3))
                                .foregroundColor(Color(hex: "eeeeee"))
                        }
                        .padding(.vertical, 8)
                        .padding(.horizontal, 13.3)
                        .background(Color(hex: "9970ff"))
                        .cornerRadius(5.3)
                        .onTapGesture {
                            onTapPurchase(.RENTAL)
                            isShowing = false
                        }
                    }
                    
                    if !isOnlyRental {
                        HStack(spacing: 0) {
                            VStack(alignment: .leading, spacing: 5.3) {
                                Text("소장")
                                    .font(.custom(Font.bold.rawValue, size: 13.3))
                                    .foregroundColor(.white)
                                
                                Text("(서비스 종료시까지)")
                                    .font(.custom(Font.light.rawValue, size: 12))
                                    .foregroundColor(.white)
                            }
                            
                            Spacer()
                            
                            HStack(spacing: 8) {
                                Image("ic_can")
                                    .resizable()
                                    .frame(width: 16.7, height: 16.7)
                                
                                Text("\(price)")
                                    .font(.custom(Font.bold.rawValue, size: 13.3))
                                    .foregroundColor(Color(hex: "eeeeee"))
                            }
                            .padding(.vertical, 8)
                            .padding(.horizontal, 13.3)
                            .background(Color(hex: "9970ff"))
                            .cornerRadius(5.3)
                            .onTapGesture {
                                onTapPurchase(.KEEP)
                                isShowing = false
                            }
                        }
                    }
                }
                .padding(24)
                .background(Color(hex: "222222"))
            }
        }
    }
}