Untitled

 avatar
unknown
plain_text
2 years ago
11 kB
6
Indexable
//
//  LabourView.swift
//  Garageworks-iOS-Revamp
//
//  Created by mac on 14/12/22.
//

import SwiftUI

struct LabourView: View {
    
    @StateObject var commonService = CommonLabourObserver(vehicle_category: UserDefaultsManager.fetchSelectedModel()?.vehicle_category ?? "", city: UserDefaultsManager.fetchSelectedArea()?.city ?? "")
    @State var selectedService: [String]
    @State private var searchService: String = ""
    @State private var issearchBarShowing: Bool = false
    @State var isHidden = false
    @State var serviceId =  UserDefaultsManager.fetchSelectedServicePackage()?.service_id ?? ""
    @Binding var manuallyEnteredServices : String
    
    var body: some View {
        GeometryReader{ geometry in
            ScrollView{
                VStack {
                    ZStack{
                        VStack {
                            Text("Do you need any specific labour services")
                                .font(Font.custom(Fonts.product_regular, size: 15))
                                .foregroundColor(Color.init(hex: Colors.color_gr2))
                                .multilineTextAlignment(.leading)
                                .frame(width:geometry.size.width*0.94,alignment: .topLeading)
                                .padding([.top], 20)
                                .padding([.leading],20)
                            
                            //Search TextField Horizontal stack
                            VStack{
                                HStack(alignment: .center, spacing: 15){
                                    Image("search-normal 1")
                                        .resizable()
                                        .frame(width: 25, height: 25)
                                        .foregroundColor(Color.init(hex: Colors.color_4a))
                                        .padding(.leading,20)
                                    CustomTextFieldPlaceHolder(placeholder: Text(Strings.label_search_services)
                                        .foregroundColor(Color.init(hex: Colors.color_b9))
                                        .font(Font.custom(Fonts.product_medium, size: 15)), text: $searchService)
                                    .cornerRadius(10)
                                    //                                .padding(.leading,5)
                                    .lineLimit(1)
                                }
                                .frame(width:geometry.size.width*0.9, height:60, alignment: .center)
                                .background(.white)
                                .cornerRadius(10)
                                .onTapGesture {
                                    issearchBarShowing.toggle()
                                }
                            }
                            .padding(.top,5)
                            
                            Text(Strings.label_common_services + "\(UserDefaultsManager.fetchSelectedModel()?.model_name ?? "")")
                                .foregroundColor(Color.init(hex: Colors.color_3f))
                                .font(Font.custom(Fonts.product_regular, size: 15))
                                .frame(width:geometry.size.width*0.94,alignment: .topLeading)
                                .padding([.leading], 10)
                                .padding([.top], 15)
                            
                            
                            //Common Complaints Rounded Buttons
                            VStack{
                                if !(commonService.commonLabourObserver?.isEmpty ?? true) {
                                WrappingHStack(models:commonService.commonLabourObserver ?? []) { tag in
                                    Button("\(tag.labour_name ?? "")", action: {
                                        debugPrint("\(tag.labour_name ?? "") pressed")
                                        if selectedService.contains(tag.labour_name ?? ""){
                                            print("Element already present")
                                        }else{
                                            ProgressView()
                                            isHidden = true
                                            selectedService.append(tag.labour_name ?? "")
                                            print("Appended array \(selectedService)")
                                            UserDefaultsManager.storeSelectedLabour(value: selectedService)
                                        }
                                    })
                                    .padding()
                                    .foregroundColor(Color.init(hex: Colors.color_wh))
                                    .font(Font.custom(Fonts.product_medium, size: 13))
                                    .frame(height: 44)
                                    .background(Color.init(hex: Colors.color_bl))
                                    .cornerRadius(20)
                                    .padding(.all,4)
                                    
                                }
//                                .padding()
//                                    .background(.white)
//                                    .frame(width:geometry.size.width*0.9)
//                                    .cornerRadius(20)
                            }
                            else{
                                Text("No common services available for : \(UserDefaultsManager.fetchSelectedModel()?.model_name ?? "")")
                                    .font(Font.custom(Fonts.product_regular, size: 13))
                                    .foregroundColor(Color.init(hex: Colors.color_b7))
                                    .frame(width: geometry.size.width - 50, height: 50, alignment: .center)
                                    .foregroundColor(.gray)
                                    .cornerRadius(20)
                            }
                            
                        }.padding()
                            .background(.white)
                            .frame(width:geometry.size.width*0.9)
                            .cornerRadius(20)
                            .padding(.top,5)
                        
                            Text(Strings.label_you_selected_following_services)
//                                 + "\(UserDefaultsManager.fetchSelectedModel()?.model_name ?? "")")
                                .foregroundColor(Color.init(hex: Colors.color_3f))
                                .font(Font.custom(Fonts.product_regular, size: 15))
                                .frame(width:geometry.size.width*0.94,alignment: .topLeading)
                                .padding([.leading], 10)
                                .padding([.top], 15)
                            
                            //Rounded button frame for selected elements
                            VStack{
                                if isHidden == false{
                                    //debugPrint("Selected list is empty")
                                    // isHidden = true
                                    Text("No Services selected")
                                        .font(Font.custom(Fonts.product_regular, size: 13))
                                        .foregroundColor(Color.init(hex: Colors.color_b7))
                                        .frame(width: geometry.size.width - 50, height: 50, alignment: .center)
                                        .foregroundColor(.gray)
                                        .cornerRadius(20)
                                    
                                }
                                WrappingHStack(models: selectedService) { selectedTag in
                                    HStack{
                                        Text("\(selectedTag)")
                                        Button(action: {
                                            debugPrint("Items deleted \(selectedTag)")
                                            selectedService = selectedService.filter{$0 != "\(selectedTag)"}
                                            if(selectedService.isEmpty)
                                            {
                                                isHidden = false
                                            }
                                        }, label: {
                                            Image("cancelButton")
                                        })
                                        
                                    }.font(.system(size: 13))
                                        .padding()
                                        .foregroundColor(Color.init(hex: Colors.color_wh))
                                        .font(Font.custom(Fonts.product_bold, size: 15))
                                        .frame(height: 44)
                                        .background(Color.init(hex: Colors.color_bl))
                                        .cornerRadius(20)
                                        .padding(.all,4)
                                }
                            }.padding()
                                .background(.white)
                                .frame(width:geometry.size.width*0.9)
                                .cornerRadius(20)
                                .padding(.top,5)
                            
                            if serviceId == "11" || serviceId == "2" {
                                Text("If you can’t find your services, please type here")
                                    .foregroundColor(Color.init(hex: Colors.color_gr2))
                                    .font(Font.custom(Fonts.product_medium, size: 15))
                                    .frame(width:geometry.size.width*0.94,alignment: .topLeading)
                                    .padding([.leading], 10)
                                    .padding([.top], 15)
                                
                                TextField("Manually Entered Services", text: $manuallyEnteredServices)
                                    .padding()
                                    .font(Font.custom(Fonts.product_regular, size: 13))
                                    .frame(width:geometry.size.width*0.9, height:60, alignment: .center)
                                    .background(.white)
                                    .cornerRadius(10)
                                    .padding([.horizontal], 10)
                                    .padding([.top], 15)
                            }
                            Spacer()
                        }
                        .frame(width:geometry.size.width, height:geometry.size.height,alignment: .top)
                        .background(Color.init(hex: Colors.color_gr))
                        .cornerRadius(30, corners: [.topLeft, .topRight])
                        LabourSearchAlertView(issearchBarShowing: $issearchBarShowing, selectLabourArray: $selectedService)
                    }
                }
            }
        }
    }
}
struct LabourView_Previews: PreviewProvider {
    static var previews: some View {
        LabourView(selectedService: [], manuallyEnteredServices: .constant(""))
    }
}
Editor is loading...