local PT = AhUI
if not PT then return end

PT.ProfessionGuides_Waypoints = {}
local W = PT.ProfessionGuides_Waypoints

function W:SetTrainerWaypoint(trainer)
    if not trainer
       or not trainer.mapID
       or not trainer.x
       or not trainer.y
    then
        print("AhUI: нет данных для установки метки")
        return
    end

    local x = trainer.x / 100
    local y = trainer.y / 100

    if C_Map
       and C_Map.SetUserWaypoint
       and UiMapPoint
    then
        local point = UiMapPoint.CreateFromCoordinates(
            trainer.mapID,
            x,
            y
        )

        C_Map.SetUserWaypoint(point)
        C_SuperTrack.SetSuperTrackedUserWaypoint(true)
    end

    if TomTom and TomTom.AddWaypoint then
        TomTom:AddWaypoint(
            trainer.mapID,
            x,
            y,
            {
                title      = trainer.name,
                persistent = false,
                minimap    = true,
                world      = true,
            }
        )
    end

    if trainer.name then
        print("Метка поставлена:", trainer.name)
    end
end

function W:SetNPCWaypoint(ref)
    if not ref
       or not ref.mapID
       or not ref.x
       or not ref.y
    then
        print("AhUI: нет данных для установки метки")
        return
    end

    local x = ref.x / 100
    local y = ref.y / 100

    if C_Map and C_Map.SetUserWaypoint and UiMapPoint then
        local point = UiMapPoint.CreateFromCoordinates(
            ref.mapID,
            x,
            y
        )
        C_Map.SetUserWaypoint(point)
        C_SuperTrack.SetSuperTrackedUserWaypoint(true)
    end

    if TomTom and TomTom.AddWaypoint then
        TomTom:AddWaypoint(
            ref.mapID,
            x,
            y,
            {
                title      = ref.name,
                persistent = false,
                minimap    = true,
                world      = true,
            }
        )
    end

    if ref.name then
        print("Метка поставлена:", ref.name)
    end
end
