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.base.BaseMapCommon
import com.abbidot.tracker.bean.FencesBean
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.ui.fragment.map.baidumap.PreviewFencesBaiduMapFragment
import com.abbidot.tracker.ui.fragment.map.googlemap.PreviewFencesGoogleMapFragment

/**
 *Created  by .yzq on 2024/4/23/023.
 * @link
 * @description:
 */
class PreviewFencesZoneCommon : BaseMapCommon() {
    private var mPreviewFencesGoogleMapFragment: PreviewFencesGoogleMapFragment? = null
    private var mPreviewFencesBaiduMapFragment: PreviewFencesBaiduMapFragment? = null

    fun getMapFragment(
        context: Context, mapLoadOk: () -> Unit
    ): Fragment {
        return if (AppUtils.isChina(AppUtils.SWITCH_MAP_TYPE)) {
            mPreviewFencesBaiduMapFragment =
                PreviewFencesBaiduMapFragment.newInstance(context, mapLoadOk)
            mPreviewFencesBaiduMapFragment!!
        } else {
            mPreviewFencesGoogleMapFragment = PreviewFencesGoogleMapFragment.newInstance(
                context, mapLoadOk
            )
            mPreviewFencesGoogleMapFragment!!
        }
    }

    /**
     * 切换地图类型
     */
    fun switchSatelliteAndNormalMapType() {
        switchSatelliteAndNormalMapType(
            mPreviewFencesBaiduMapFragment, mPreviewFencesGoogleMapFragment
        )
    }

    /**
     * 设置宠物位置经纬度
     */
    fun setPetCurrentLocation(petHeadUrl: String, petType: Int, lat: Double, lon: Double) {
        setPetHeadAndCurrentLocation(
            petHeadUrl,
            petType,
            lat,
            lon,
            mPreviewFencesBaiduMapFragment,
            mPreviewFencesGoogleMapFragment
        )
    }

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

    /**
     * 根据预览围栏类型设置地图等级
     * @param padding 距离屏幕边缘的距离,px单位
     */
    fun restorePreviewFencesSetMapZoom(
        context: Context, fencesBean: FencesBean, padding: Int = AppUtils.dpToPx(50)
    ) {
        restoreFencesSetMapZoom(
            context,
            fencesBean,
            mPreviewFencesBaiduMapFragment,
            mPreviewFencesGoogleMapFragment,
            padding
        )
    }
}