//
//  NotificationSettingsView.swift
//  SodaLive
//
//  Created by klaus on 2023/08/10.
//

import SwiftUI

struct NotificationSettingsView: View {
    
    @StateObject var viewModel = NotificationSettingsViewModel()
    
    var body: some View {
        BaseView(isLoading: $viewModel.isLoading) {
            VStack(spacing: 0) {
                DetailNavigationBar(title: "알림 설정")
                
                ScrollView(.vertical, showsIndicators: false) {
                    VStack(spacing: 0) {
                        HStack(spacing: 0) {
                            Text("라이브 알림")
                                .font(.custom(Font.bold.rawValue, size: 15))
                                .foregroundColor(Color(hex: "eeeeee"))
                            
                            Spacer()
                            
                            Image(viewModel.followingChannelLive ? "btn_toggle_on_big" : "btn_toggle_off_big")
                                .resizable()
                                .frame(width: 44, height: 27)
                                .onTapGesture {
                                    viewModel.followingChannelLive.toggle()
                                }
                        }
                        .frame(height: 50)
                        
                        Rectangle()
                            .frame(height: 1)
                            .foregroundColor(Color(hex: "909090").opacity(0.3))
                        
                        HStack(spacing: 0) {
                            Text("콘텐츠 업로드 알림")
                                .font(.custom(Font.bold.rawValue, size: 15))
                                .foregroundColor(Color(hex: "eeeeee"))
                            
                            Spacer()
                            
                            Image(viewModel.followingChannelUploadContent ? "btn_toggle_on_big" : "btn_toggle_off_big")
                                .resizable()
                                .frame(width: 44, height: 27)
                                .onTapGesture {
                                    viewModel.followingChannelUploadContent.toggle()
                                }
                        }
                        .frame(height: 50)
                        
                        Rectangle()
                            .frame(height: 1)
                            .foregroundColor(Color(hex: "909090").opacity(0.3))
                        
                        HStack(spacing: 0) {
                            Text("메시지 알림")
                                .font(.custom(Font.bold.rawValue, size: 15))
                                .foregroundColor(Color(hex: "eeeeee"))
                            
                            Spacer()
                            
                            Image(viewModel.message ? "btn_toggle_on_big" : "btn_toggle_off_big")
                                .resizable()
                                .frame(width: 44, height: 27)
                                .onTapGesture {
                                    viewModel.message.toggle()
                                }
                        }
                        .frame(height: 50)
                    }
                    .padding(.vertical, 6.7)
                    .padding(.horizontal, 13.3)
                    .background(Color(hex: "222222"))
                    .cornerRadius(10)
                    .padding(.top, 26.7)
                    .padding(.horizontal, 13.3)
                }
            }
            .onAppear {
                viewModel.getMemberInfo()
            }
        }
        .popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
            GeometryReader { geo in
                HStack {
                    Spacer()
                    Text(viewModel.errorMessage)
                        .padding(.vertical, 13.3)
                        .padding(.horizontal, 6.7)
                        .frame(width: geo.size.width - 66.7, alignment: .center)
                        .font(.custom(Font.medium.rawValue, size: 12))
                        .background(Color(hex: "3bb9f1"))
                        .foregroundColor(Color.white)
                        .multilineTextAlignment(.leading)
                        .fixedSize(horizontal: false, vertical: true)
                        .cornerRadius(20)
                        .padding(.top, 66.7)
                    Spacer()
                }
            }
        }
    }
}

struct NotificationSettingsView_Previews: PreviewProvider {
    static var previews: some View {
        NotificationSettingsView()
    }
}
