//
//  MoreView.swift
//  Toolboxes
//
//  Created by 研发2组 on 2024/9/21.
//

import SwiftUI

@available(iOS 16.0, *)
struct MoreView: View {
    @State private var showHorizontalGlobe: Bool = true
    @State private var showAuxiliaryLine: Bool = true
    @State private var showCompass: Bool = true

   
    var body: some View {
        VStack(spacing: 20.0){
            Image("more_topbg")
                .resizable()
                .scaledToFit()
                .ignoresSafeArea(edges: .top)
            
            VStack(spacing: 20.0){
                // Button Section
                HStack(alignment: .bottom,spacing: 20) {
                    NavigationLink(destination: FlashlightView()) {
                        RoundedRectangle(cornerRadius: 20)
                            .fill(Color.white)
                            .overlay(
                                VStack{
                                    Image("more_signal")
                                    Text("Survival lights")
                                        .font(.headline)
                                        .foregroundColor(.black)
                                }.background(Color.white)
                                
                            )
                       
                    }

                    NavigationLink(destination: WidgetListView()) {
                        RoundedRectangle(cornerRadius: 20)
                            .fill(Color.white)
                            .overlay(
                                VStack{
                                    Image("more_widget")
                                    Text("Widgets List")
                                        .font(.headline)
                                        .foregroundColor(.black)
                                }
                                
                            )

                    }
                }
                .frame(height: 130)
               
                VStack(spacing: 20.0){
                    RoundedRectangle(cornerRadius: 20)
                        .fill(Color.white)
                        .frame(height: 180)

                        .overlay(
                            VStack{
                                Toggle(isOn: $showHorizontalGlobe) {
                                    Text("Show the horizontal ball")
                                }
                                .tint(Color.customdeepblue)
                                .frame(height: 59.0)
                                .onChange(of: showHorizontalGlobe) { newValue in
                                    UserDefaults.standard.set(newValue, forKey: "showHorizontalGlobe")
                                }
                                
                                Spacer().frame(height: 1.0).background(Color.customWhite)
                                
                                Toggle(isOn: $showAuxiliaryLine) {
                                    Text("Compass shows auxiliary line")
                                }
                                .tint(Color.customdeepblue)
                                .frame(height: 59.0)
                                .onChange(of: showAuxiliaryLine) { newValue in
                                    UserDefaults.standard.set(newValue, forKey: "showAuxiliaryLine")
                                }
                                
                                Spacer().frame(height: 1.0).background(Color.customWhite)
                                
                                Toggle(isOn: $showCompass) {
                                    Text("Positioning display compass")
                                }
                                .tint(Color.customdeepblue)
                                .frame(height: 59.0)
                                .onChange(of: showCompass) { newValue in
                                    UserDefaults.standard.set(newValue, forKey: "showCompass")
                                }
                            }
                                .padding( .horizontal , 20.0)
                            
                        )
                    RoundedRectangle(cornerRadius: 20)
                        .fill(Color.white)
                        .frame(height: 120)
                        .overlay(
                            VStack{
                                Link(destination: URL(string: "http://7.ln.cn/private.html")!) {
                                                     HStack {
                                                         Text("Privacy Policy")
                                                             .foregroundColor(.black)
                                                         Spacer()
                                                         Image(systemName: "chevron.right")
                                                     }
                                                     .frame(height: 59.0)
                                                     .foregroundColor(.black)
                                                 }
                                Spacer().frame(height: 1.0).background(Color.customWhite)
                                
                                HStack {
                                    Text("Version")
                                    Spacer()
                                    Text("1.0.0")
                                }
                                .frame(height: 59.0)
                             
                            }
                                .padding( .horizontal , 20.0)
                            
                        )
                   
                }
            } .padding( .top , -200.0) .padding( .horizontal , 20.0)

            Spacer()
        }
        .gradientBackground()
        .navigationBarHidden(true)
        .onAppear(){
            showHorizontalGlobe = UserDefaults.standard.bool(forKey: "showHorizontalGlobe")
            showAuxiliaryLine = UserDefaults.standard.bool(forKey: "showAuxiliaryLine")
            
            showCompass = UserDefaults.standard.bool(forKey: "showCompass")
        }
    }
}


@available(iOS 16.0, *)
struct MoreView_Previews: PreviewProvider {
    static var previews: some View {
        MoreView()
    }
}
