package com.abbidot.tracker.ui.common.map

import android.content.Context
import androidx.fragment.app.Fragment
import com.abbidot.baselibrary.util.AppUtils
import com.abbidot.tracker.R
import com.abbidot.tracker.base.BaseMapCommon
import com.abbidot.tracker.bean.WiFiZoneBean
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.deprecated.ui.fragment.map.baidumap.NavigationBaiduMapFragment
import com.abbidot.tracker.ui.fragment.map.googlemap.EditWiFiZoneGoogleMapFragment

/**
 *Created  by .yzq on 2024/6/4/004.
 * @link
 * @description:
 */
class EditWifiZoneMapCommon : BaseMapCommon() {

    private var mEditZoneGoogleMapFragment: EditWiFiZoneGoogleMapFragment? = null
    private var mBaiduMapFragment: NavigationBaiduMapFragment? = null

    fun getMapFragment(
        context: Context, wiFiZoneBean: WiFiZoneBean, mapLoadOk: () -> Unit
    ): Fragment {
        return if (AppUtils.isChina(AppUtils.SWITCH_MAP_TYPE)) {
            mBaiduMapFragment = NavigationBaiduMapFragment.newInstance(context)
            mBaiduMapFragment!!
        } else {
            mEditZoneGoogleMapFragment =
                EditWiFiZoneGoogleMapFragment.newInstance(context, wiFiZoneBean, mapLoadOk)
            mEditZoneGoogleMapFragment!!
        }
    }

    /**
     * 设置显示wifi的位置
     */
    fun setShowWifiLocation(lat: Double, lon: Double, isDraggable: Boolean) {
        mEditZoneGoogleMapFragment?.apply {
            moveCameraLocation(lat, lon)
            addImageMarker(lat, lon, R.drawable.icon_location_svg, false, isDraggable)
        }
    }

    /**
     * 切换地图类型
     */
    fun switchSatelliteAndNormalMapType() {
        switchSatelliteAndNormalMapType(mBaiduMapFragment, mEditZoneGoogleMapFragment)
    }

    /**
     * 切换用户、宠物和围栏的位置居中显示
     */
    fun switchShowLocation(@ConstantInt type: Int, lat: Double, lon: Double) {
        switchShowLocationType(
            type, lat, lon, mBaiduMapFragment, mEditZoneGoogleMapFragment
        )
    }

    /**
     * 设置宠物的经纬度，方便切换显示位置
     */
    fun setPetLatLon(petImageUrl: String, petType: Int, lat: Double, lon: Double) {
        if (lat == 0.0 && lon == 0.0) return
        mEditZoneGoogleMapFragment?.setPetCurrentLocation(petImageUrl, lat, lon, petType)
    }
}