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

import Foundation
import CoreLocation


let appGroupDefaults = UserDefaults(suiteName: "group.com.yhgc.Toolboxes.identifier")

//#if targetEnvironment(simulator)
//        print("模拟器不支持指南针功能")
//#else
//        do {
//
//            try   let latitude = appGroupDefaults?.double(forKey: "latitude") ?? 0
//            let longitude = appGroupDefaults?.double(forKey: "longitude") ?? 0
//            let altitude = appGroupDefaults?.double(forKey: "altitude") ?? 0
//        } catch {
//            print("无法启动指南针功能: \(error)")
//        }
//#endif

func L(_ key: String) -> String {
    return NSLocalizedString(key, comment: "")
}

func getCurrentFormattedDate() -> String {
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "yyyy.MM.dd"
    return dateFormatter.string(from: Date())
}

// 扩展 CLLocationDegrees 用于转换经纬度为 DMS 格式
extension CLLocationDegrees {
    func toDMS() -> String {
        let degrees = Int(self)
        let minutesDecimal = abs(self - Double(degrees)) * 60
        let minutes = Int(minutesDecimal)
        let seconds = (minutesDecimal - Double(minutes)) * 60
        return String(format: "%d°%02d′%02.0f″", degrees, minutes, seconds)
    }
}

// 示例：转换经纬度
func convertCoordinatesToDMS(latitudeAsDouble: String, longitudeAsDouble: String) -> (latitudeDMS: String, longitudeDMS: String) {
    // 由于 CLLocationDegrees 是 Double 的别名，我们可以直接赋值
    let latitude: CLLocationDegrees = Double(latitudeAsDouble)!
    let longitude: CLLocationDegrees = Double(longitudeAsDouble)!
    let latitudeDMS = latitude.toDMS()
    let longitudeDMS = longitude.toDMS()
    return (latitudeDMS, longitudeDMS)
}


