//
//  FilterViewGroup.swift
//  GreensChronics
//
//  Created by Roman on 21.07.21.
//

import SwiftUI

struct FilterViewGroup: View {
    
    @State private var extendedView: Bool = false
    @EnvironmentObject var appModel: AppModel
    @EnvironmentObject var greensModel: GreensModel
    @EnvironmentObject var gridVM: GridViewModel
    var geo: GeometryProxy
    
    @Binding var selectedMonth: SelectedMonth
    
    var filterViewContent: some View {
        Group {
            switch extendedView {
            case true:
                FilterView(months: greensModel.months, selectedMonth: $selectedMonth)
                    .environmentObject(gridVM)
            case false:
                EmptyView()
            }
        }
    }
    
    var body: some View {
        VStack(alignment: .leading) {
            HStack {
                Text("Filter").fontWeight(.bold)
                Button(action: {
                    withAnimation(.linear(duration: appModel.animationDuration).delay(appModel.animationDelay)) {
                        extendedView.toggle()
                    }
                }, label: {
                    Image(systemName: "chevron.right.circle")
                        .rotationEffect(.degrees(extendedView ? 90 : 0))
                })
                .buttonStyle(PlainButtonStyle())
                ClearFilterButton($selectedMonth)
            }
            .padding(.bottom, 12)
            filterViewContent
        }
        .padding(.leading, 12)
        .padding(.bottom, 24)
        .padding(.top, 12)
    }
}
