//
//  LiveCancelDialog.swift
//  SodaLive
//
//  Created by klaus on 2023/08/14.
//

import SwiftUI

struct LiveCancelDialog: View {
    
    @Binding var isShowCancelPopup: Bool
    let confirmAction: (String) -> Void
    
    @State var reason: String = ""
    var placeholder = "취소사유를 입력하세요"
    
    var body: some View {
        VStack(spacing: 0) {
            Text("예약취소")
                .font(.custom(Font.bold.rawValue, size: 18.3))
                .foregroundColor(Color(hex: "bbbbbb"))
                .padding(.top, 40)
            
            TextViewWrapper(
                text: $reason,
                placeholder: placeholder,
                textColorHex: "eeeeee",
                backgroundColorHex: "333333"
            )
            .frame(width: screenSize().width - 53.4, height: 150)
            .cornerRadius(6.7)
            .overlay(
                RoundedRectangle(cornerRadius: 6.7)
                    .stroke(Color(hex: "3bb9f1"), lineWidth: 1.3)
            )
            .padding(.top, 13.3)
            
            HStack(spacing: 13.3) {
                Text("취소")
                    .font(.custom(Font.bold.rawValue, size: 18.3))
                    .foregroundColor(Color(hex: "3bb9f1"))
                    .padding(.vertical, 16)
                    .padding(.horizontal, 48)
                    .background(Color(hex: "13181b"))
                    .cornerRadius(10)
                    .overlay(
                        RoundedRectangle(cornerRadius: 10)
                            .stroke(Color(hex: "3bb9f1"), lineWidth: 1.3)
                    )
                    .onTapGesture {
                        isShowCancelPopup = false
                    }
                
                Text("확인")
                    .font(.custom(Font.bold.rawValue, size: 18.3))
                    .foregroundColor(.white)
                    .padding(.vertical, 16)
                    .padding(.horizontal, 48)
                    .background(Color(hex: "3bb9f1"))
                    .cornerRadius(10)
                    .onTapGesture {
                        confirmAction(reason.trimmingCharacters(in: .whitespacesAndNewlines) != placeholder ? reason : "")
                        isShowCancelPopup = false
                    }
            }
            .padding(.top, 45)
            .padding(.bottom, 16.7)
        }
        .frame(width: screenSize().width - 26.7)
        .background(Color(hex: "222222"))
        .cornerRadius(10)
        .onAppear {
            UITextView.appearance().backgroundColor = .clear
        }
    }
}
