---@type Orbit
local Orbit = Orbit
local L = Orbit.L

local TOF_FRAME_INDEX = 101

local Plugin = Orbit:RegisterPlugin("Target of Focus", "Orbit_TargetOfFocusFrame", {
    displayName = L.PLG_NAME_TARGET_OF_FOCUS,
    canvasMode = true,
    defaults = Orbit.SecondaryUnitFrameMixin.sharedDefaults,
})

Mixin(Plugin, Orbit.UnitFrameMixin)
Mixin(Plugin, Orbit.SecondaryUnitFrameMixin)

function Plugin:IsEnabled()
    return Orbit:ReadPluginSetting("Orbit_FocusFrame", Enum.EditModeUnitFrameSystemIndices.Focus, "EnableFocusTarget") == true
end

function Plugin:AddSettings(dialog, systemFrame) self:AddSecondarySettings(dialog, systemFrame) end

function Plugin:OnLoad()
    self:CreateSecondaryPlugin({
        unit = "focustarget", parentUnit = "focus",
        frameName = "OrbitTargetOfFocusFrame", editModeName = self.displayName,
        frameIndex = TOF_FRAME_INDEX,
        nativeFrame = FocusFrameToT,
        changeEvent = "PLAYER_FOCUS_CHANGED",
        defaultX = -200, defaultY = -180,
        exposeMountedConfig = true,
        vePluginName = "Focus Frame",
    })
    Orbit.EventBus:On("ORBIT_FOCUS_SETTINGS_CHANGED", function() self:UpdateVisibility() end, self)
end
