

import WidgetKit
import SwiftUI

struct AltitudeSmallView: View {
    let data: [ String:String]
    let scalefont : Double = 0.15
    
    var body: some View {
      
        GeometryReader { geometry in
            HStack{
                VStack(alignment: .leading) {
                    
                    Text(L("Altitude"))
                        .font(.system(size: geometry.size.height * scalefont, weight: .bold))
                    
                    Text(String(format: "%.1fm", Double(data["altitude"]!)!))
                        .font(.system(size: geometry.size.height * scalefont * 0.8, weight: .bold))
                        .foregroundColor(.customdeepblue)
                        .lineLimit(1)
                     
                    Spacer()
                
                    Text("\(L("Latitude")):\(  convertCoordinatesToDMS(latitudeAsDouble: data["latitude"]!, longitudeAsDouble: data["longitude"]!).latitudeDMS)")
                        .font(.system(size: geometry.size.height * scalefont * 0.6))
                        .lineLimit(1)
                    
                    Text("\(L("Longitude")):\(convertCoordinatesToDMS(latitudeAsDouble: data["latitude"]!, longitudeAsDouble: data["longitude"]!).longitudeDMS)")
                        .font(.system(size: geometry.size.height * scalefont * 0.6))
                        .lineLimit(1)
                  
                }
              
                .padding([.leading,.top,.bottom], geometry.size.width * 0.1)
                .frame(maxHeight: .infinity)
                
                Spacer()
                
                ZStack(alignment: .topLeading){
                
                    HStack{
                        Image("altitude_ruler")
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(height: geometry.size.height )
                            
                    }
                    
                    .padding([.leading,.trailing],5).frame(height: geometry.size.height)
                   
                    HStack(spacing: 0.0){
                        VStack(alignment: .leading){
                            
                            Spacer().frame(height: Double(1.0 - Double(data["altitude"]!)!/10000.0) * geometry.size.height - geometry.size.width * 0.1 * 0.75)
//                            "altitude_point"
                            Image("altitude_point")
                                .resizable() // 确保图像可调整大小
                                .aspectRatio(contentMode: .fit)
                                .frame(width: geometry.size.width * 0.1,height: geometry.size.width * 0.1 * 0.75)
                            
                            Spacer()
                        }

                    } 
                }
                .background(Color.white)
            
            }  .gradientBackground(colors: [.customgradient_top, .customgradient_bottom])
        }
    }
}

struct AltitudeSmallView_Previews: PreviewProvider {
    static var previews: some View {
  
        AltitudeSmallView(data: ["latitude":"\(0.00)","longitude":"\(0.00)","altitude":"\(3.00)"])
    }
}
