//
//  CreatorFollowNotifyDialog.swift
//  SodaLive
//
//  Created by klaus on 9/23/24.
//

import SwiftUI

struct CreatorFollowNotifyDialog: View {
    
    @Binding var isShowing: Bool
    let onClickNotifyAll: () -> Void
    let onClickNotifyNone: () -> Void
    let onClickUnFollow: () -> Void
    
    @State private var isShow: Bool = false
    
    var body: some View {
        ZStack {
            Color.black.opacity(0.7).ignoresSafeArea()
                .onTapGesture {
                    isShowing = false
                }
            
            VStack(spacing: 0) {
                Spacer()
                
                if isShow {
                    VStack(alignment: .leading, spacing: 24) {
                        Text("알림")
                            .font(.custom(Font.bold.rawValue, size: 18.3))
                            .foregroundColor(Color.grayee)
                        
                        CreatorFollowNotifyItem(
                            image: "ic_notify_all",
                            title: "전체",
                            onTapGesture: {
                                isShowing = false
                                onClickNotifyAll()
                            }
                        )
                        CreatorFollowNotifyItem(
                            image: "ic_notify_none",
                            title: "없음",
                            onTapGesture: {
                                isShowing = false
                                onClickNotifyNone()
                            }
                        )
                        CreatorFollowNotifyItem(
                            image: "ic_avatar_unfollow",
                            title: "팔로우 취소",
                            onTapGesture: {
                                isShowing = false
                                onClickUnFollow()
                            }
                        )
                    }
                    .frame(maxWidth:.infinity)
                    .padding(.horizontal, 16)
                    .padding(.top, 16)
                    .padding(.bottom, 32)
                    .background(Color.gray22)
                    .cornerRadius(10, corners: [.topLeft, .topRight])
                    .transition(.move(edge: .bottom))
                    .animation(.easeInOut(duration: 0.5), value: isShow)
                }
            }
            .ignoresSafeArea()
        }
        .onAppear {
            withAnimation {
                isShow = true
            }
        }
    }
}

struct CreatorFollowNotifyItem: View {
    
    let image: String
    let title: String
    let onTapGesture: () -> Void
    
    var body: some View {
        HStack(spacing: 16) {
            Image(image)
            
            Text(title)
                .font(.custom(Font.medium.rawValue, size: 13.3))
                .foregroundColor(Color.grayee)
            
            Spacer()
        }
        .contentShape(Rectangle())
        .onTapGesture(perform: onTapGesture)
    }
}

#Preview {
    CreatorFollowNotifyDialog(
        isShowing: .constant(true),
        onClickNotifyAll: {},
        onClickNotifyNone: {},
        onClickUnFollow: {}
    )
}