-----------------------
-- 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:SetScript("OnUpdate", self.dragingFrame._update)
  end)

  button:SetScript("OnDragStop", function(self)
    self.dragingFrame:SetScript("OnUpdate", nil)
  end)
  
  -- TODO: Move the tooltip code into it's own function.
  -- Add the tooltip.
  button.tAnchor = "ANCHOR_NONE"
  button.tPoint = {
    "RIGHT",
    button,
    "LEFT",
  }
  button.tLines = {
    "Seamore Spheres",
    "",
    ss.T["open_menu"],
    ss.T["move_sphere"],
  }
  
  ss.Utils:SetTooltip(button)

  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)
