//
//  EmptyView.swift
//  Reflect (iOS)
//
//  Created by Trey Tartt on 2/10/22.
//

import SwiftUI

struct EmptyHomeView: View {
    @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system

    private var textColor: Color { theme.currentTheme.labelColor }

    let showVote: Bool
    let viewModel: DayViewViewModel?
    
    var body: some View {
        ZStack {
            theme.currentTheme.secondaryBGColor
            
            VStack {
                if showVote {
                    AddMoodHeaderView(addItemHeaderClosure: { (mood, date) in
                        withAnimation {
                            viewModel?.add(mood: mood, forDate: date, entryType: .header)
                        }
                    })
                } else {
                    VStack {
                        Spacer()
                        Text(String(localized: "view_no_data"))
                            .font(.title)
                            .padding()
                            .fixedSize(horizontal: false, vertical: true)
                            .foregroundColor(textColor)
                            .accessibilityIdentifier(AccessibilityID.DayView.emptyStateNoData)
                        Spacer()
                    }
                }
            }
        }
        .fixedSize(horizontal: false, vertical: true)
        .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
    }
}

struct EmptyHomeView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            EmptyHomeView(showVote: true, viewModel: DayViewViewModel(addMonthStartWeekdayPadding: false))
            
            EmptyHomeView(showVote: false, viewModel: nil)
        }
    }
}
