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

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

local mtMapButton = {};

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:MakeFrameMovable(button)

  button:SetScript("OnLoad", function(self)
    self:RegisterForDrag("LeftButton")
    self:RegisterForClicks("LeftButtonUp","RightButtonUp")
    self:SetPoint("TOPLEFT","Minimap","TOPLEFT", ss.global.general.MapMarker.x, ss.global.general.MapMarker.y)
  end)

  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) self.tooltip:Hide(); end)
  button:SetScript("OnEnter",     function(self)
    self.tooltip:ClearLines()
    self.tooltip:SetOwner(self,"CENTER")
    self.tooltip:AddLine("Seamore Spheres")
    self.tooltip:AddLine("Left click to open the menu")
    self.tooltip:AddLine("Hold Shift and Drag on any sphere to move it.")
    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["MapMarkerButton"] = setmetatable({}, { __index = mtMapButton });
