//
//  SideBarView.swift
//  Kula
//
//  Created by Cédric Bahirwe on 27/07/2021.
//

import SwiftUI

struct SideBarView: View {
    @AppStorage("hasFinishedOnBoard")
    var hasFinishedOnBoard: Bool = false
    
    @Binding var isShown: Bool
    var body: some View {
        HStack {
            VStack(alignment: .leading) {
                HStack {
                    ABCLogo()
                    
                    Spacer()
                    Image(systemName: "x.circle")
                        .resizable()
                        .frame(width: 30, height: 30)
                        .onTapGesture {
                            isShown.toggle()
                        }
                }
                .padding(10)
                .foregroundColor(.redar)
                
                VStack(alignment: .leading, spacing: 5) {
                    Text("ABC Group Market")
                        .font(Font(UIFont(name: "Futura", size: 20)!))
                        .bold()
                        .foregroundColor(.white)
                    
                    Link("abc.incs.001@gmail.com",
                         destination: URL(string: "mailto:abc.incs.001@gmail.com")!)
                        .frame(height: 30)
                        .foregroundColor(.redar)
                }
                .padding(.horizontal)
                
                ScrollView {
                    VStack(alignment: .leading, spacing: 0) {
                        Button(action: {}, label: {
                            Label("Create an account", systemImage: "person.fill.badge.plus")
                                .frame(height: 45)
                        })
                        
                        Button(action: {}, label: {
                            Label("Connect", systemImage: "person.badge.plus.fill")
                                .frame(height: 45)
                        })
                        Button(action: {}, label: {
                            Label("Your orders", systemImage: "cart.fill.badge.plus")
                                .frame(height: 45)
                        })
                        Button(action: {}, label: {
                            Label("Cart", systemImage: "cart")
                                .frame(height: 45)
                        })
                        
                        Color.gray.frame(height: 0.7)
                        Button(action: {}, label: {
                            Label("Info", systemImage: "exclamationmark.circle.fill")
                                .frame(height: 45)
                        })
                        Button(action: {}, label: {
                            Label("Your account", systemImage: "person.crop.circle.fill.badge.checkmark")
                                .frame(height: 45)
                        })
                        
                        Button(action: {
                            hasFinishedOnBoard.toggle()
                            
                        }, label: {
                            
                            Label("Log out ", systemImage: "person.crop.circle.badge.xmark")
                                .foregroundColor(.red)
                                .frame(height: 45)
                        })
                        
                    }
                    .frame(maxWidth: .infinity, alignment: .leading)
                   
                }
                .padding(.horizontal)

            }
            
            .foregroundColor(Color(UIColor.lightGray))
            .frame(width: size.width*0.73)
            .background(Color.dark.ignoresSafeArea(.all, edges: .vertical))
            
            Spacer()
        }
    }
}

struct SideBarView_Previews: PreviewProvider {
    static var previews: some View {
        SideBarView(isShown: .constant(true))
    }
}
