//
//  AboutAppView.swift
//  Sailassist
//
//  Created by 三浦薫巳 on 2023/12/21.
//
import SwiftUI
import PDFKit

enum Policy: String, Hashable{
    case TermsOfUse
    case PrivacyStatement

    var title: String{
        switch self {
        case .TermsOfUse:
            "Terms Of Use"
        case .PrivacyStatement:
            "Privacy Statement"
        }
    }
}

struct AboutAppView: View {
    @State var policy: Policy = .TermsOfUse
    let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String

    var body: some View {
        VStack{
            HStack {
                VStack(alignment: .leading, spacing: 10){
                    Text("Version")
                        .font(FontStyle.SupplementText.font)
                        .foregroundColor(ColorSet.BodyDescriptiion.color)
#if CANARY
                    Text("\(version)" + " Canary")
                        .font(FontStyle.SupplementText.font)
                        .foregroundColor(ColorSet.Body.color)
                        .padding(.leading, 20)
#elseif QC
                    Text("\(version)" + " QC")
                        .font(FontStyle.TitleS.font)
                        .foregroundColor(ColorSet.Body.color)
#else
                    Text("\(version)")
                        .font(FontStyle.TitleS.font)
                        .foregroundColor(ColorSet.Body.color)
#endif
                }
                .padding(.horizontal, 30)
                .padding(.vertical, 17)
                Spacer()
            }
            Divider()
                .background(ColorSet.LineColor04.color)

            Spacer().frame(height: 50)

            Text("Policy")
                .font(FontStyle.SupplementText.font)
                .foregroundColor(ColorSet.BodyDescriptiion.color)
                .frame(maxWidth: .infinity, alignment: .leading)
                .padding(.leading, 30)

            Divider()
                .background(ColorSet.LineColor04.color)

            HStack {
                NavigationLink {
                    LocalWebView(policy: .constant(.TermsOfUse))
                } label: {
                    Text("Terms of Use")
                        .font(FontStyle.EmphasisText.font)
                        .foregroundColor(ColorSet.Body.color)

                    Spacer()

                    Image("ink_01")
                        .resizable()
                        .frame(width: 22, height: 22)
                }
                .padding(.vertical, 17)
                .padding(.horizontal, 30)
            }

            HStack {
                NavigationLink {
                    LocalWebView(policy: .constant(.PrivacyStatement))
                } label: {
                    Text("Privacy Statement")
                        .font(FontStyle.EmphasisText.font)
                        .foregroundColor(ColorSet.Body.color)

                    Spacer()

                    Image("ink_01")
                        .resizable()
                        .frame(width: 22, height: 22)
                }
                .padding(.vertical, 17)
                .padding(.horizontal, 30)
            }

            Spacer().frame(height: 50)
            Text("Open Source Licenses")
                .font(FontStyle.SupplementText.font)
                .foregroundColor(ColorSet.BodyDescriptiion.color)
                .frame(maxWidth: .infinity, alignment: .leading)
                .padding(.leading, 30)

            Divider()
                .background(ColorSet.LineColor04.color)

            Text("Azure Notification Hubs SDK for Apple")
                .font(FontStyle.EmphasisText.font)
                .foregroundColor(ColorSet.Body.color)
                .frame(maxWidth: .infinity, alignment: .leading)
                .padding(.leading, 50)
                .padding(.top, 17)

            VStack(spacing: 30) {
                
                Link("https://github.com/Azure/azure-notificationhubs-ios/blob/main/LICENSE", destination: URL(string: HttpRequestType.ApachLicens.rawValue)!)
            }
            .padding(.top, 2)
            .padding(.horizontal, 50)
            .font(FontStyle.RadioButtonText.font)
            .foregroundColor(ColorSet.Body.color)
            Spacer()
        }
        .background(ColorSet.BackgroundPrimary.color)
    }
}

#Preview {
    AboutAppView()
}
