-----------------------
-- Map Marker Button --
-----------------------
local addon, ns = ...
local ss = ns.SS

local CreateFrame, Minimap = CreateFrame, Minimap
local sin, cos = sin, cos

local mtMapButton = {};

--- Creates a new map button.
--
function mtMapButton:New()
  -- Create map button
  local button = CreateFrame("Button", ss._f.."MapButton", Minimap)

  button:SetWidth      (ss.private.MapMarker.size)
  button:SetHeight     (ss.private.MapMarker.size)
  button:SetFrameStrata("LOW")
  button:SetPoint      ("TOPLEFT", 0, 0)
  
  ss.Utils:MakeFrameMovable(button)

  button:SetScript("OnClick",     function() ss:ToggleConfig(); end)
  button:SetScript("OnDragStart", function(self) self.dragingFrame:Show(); end)
  button:SetScript("OnDragStop",  function(self) self.dragingFrame:Hide(); end)
  button:SetScript("OnLeave",     function(self)
    if self.tooltip:IsVisible() then
      self.tooltip:Hide()
    end
  end)
  button:SetScript("OnEnter",     function(self)
    self.tooltip:ClearLines()
    self.tooltip:SetOwner  (self,"CENTER")
    self.tooltip:AddLine   ("Seamore Spheres")
    self.tooltip:AddLine   (ss.T["open_menu"])
    self.tooltip:AddLine   (ss.T["move_sphere"])
    self.tooltip:Show()
  end)

  function button:Reposition(locationAngle)
    local x = 52-(80*cos(locationAngle))
    local y = ((80*sin(locationAngle))-52)
    self:SetPoint("TOPLEFT","Minimap","TOPLEFT", x, y)

    ss.global.general.MapMarker.x             = x
    ss.global.general.MapMarker.y             = y
    ss.global.general.MapMarker.locationAngle = locationAngle
  end

  button:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight", "ADD")

  return button
end

ss.Utils.addModule("MapMarkerButton", mtMapButton)
