local SHOW_BACK_TO_TOC_OPTION = true
local HIDE_BACK_TO_TOC_OPTION = false

local COST_OPTION_TO_PROMPT =
{
    [CHATTER_TALK_CHOICE_MONEY]      = GetString(SI_PAY_FOR_CONVERSATION_GIVE),
    [CHATTER_TALK_CHOICE_PAY_BOUNTY] = GetString(SI_PAY_FOR_CONVERSATION_GIVE),
}

local COST_OPTION_TO_PROMPT_TITLE =
{
    [CHATTER_TALK_CHOICE_MONEY]      = GetString(SI_PAY_FOR_CONVERSATION_GIVE_TITLE),
    [CHATTER_TALK_CHOICE_PAY_BOUNTY] = GetString(SI_PAY_FOR_CONVERSATION_GIVE_TITLE),
}

CHATTER_OPTION_ERROR =
{
    [CHATTER_TALK_CHOICE_MONEY] = SI_ERROR_CANT_AFFORD_OPTION,
    [CHATTER_TALK_CHOICE_INTIMIDATE_DISABLED] = SI_ERROR_NEED_INTIMIDATE,
    [CHATTER_TALK_CHOICE_PERSUADE_DISABLED] = SI_ERROR_NEED_PERSUADE,
    [CHATTER_GUILDKIOSK_IN_TRANSITION] = SI_INTERACT_TRADER_BIDDING_CLOSED_DURING_BID_TRANSITIONING_PERIOD,
    [CHATTER_TALK_CHOICE_PAY_BOUNTY] = SI_ERROR_CANT_AFFORD_OPTION,
    [CHATTER_TALK_CHOICE_CLEMENCY_DISABLED] = SI_ERROR_NEED_CLEMENCY,
    [CHATTER_TALK_CHOICE_CLEMENCY_COOLDOWN] = SI_ERROR_CLEMENCY_ON_COOLDOWN,
}


do
    local function UpdatePlayerGold(control)
        ZO_CurrencyControl_SetSimpleCurrency(control, CURT_MONEY, GetCarriedCurrencyAmount(CURT_MONEY), ZO_GAMEPAD_CURRENCY_OPTIONS_LONG_FORMAT)
        return true
    end
    function ZO_SharedInteraction:HandleChatterOptionClicked(label)

        TashDialogueLog:OnChatterOptionClicked(label)

        --if it's not enabled, report why it cant be used and return
        if(not label.enabled) then
            local errorStringId = CHATTER_OPTION_ERROR[label.optionType]
            if(errorStringId) then
                ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, errorStringId)
            end
            return
        end

        if(label.optionIndex) then
            local oiType = type(label.optionIndex)
            if(oiType == "number") then
                --popup a dialog if it's an option with a cost and the cost is greater than free
                if(COST_OPTION_TO_PROMPT[label.optionType] and label.gold and label.gold > 0) then
                    ZO_Dialogs_ShowPlatformDialog(
                        "PAY_FOR_CONVERSATION",
                        {
                            chatterOptionIndex = label.optionIndex,
                            data1 = {
                                header = GetString(SI_GAMEPAD_PAY_FOR_CONVERSATION_AVAILABLE_FUNDS),
                                value = UpdatePlayerGold,
                            },
                        },
                        {
                            titleParams = { COST_OPTION_TO_PROMPT_TITLE[label.optionType] },
                            mainTextParams = {COST_OPTION_TO_PROMPT[label.optionType], label.gold, ZO_Currency_GetPlatformFormattedGoldIcon()}
                        }
                    )
                    --otherwise just do it
                else
                    SelectChatterOption(label.optionIndex)
                end
            elseif(oiType == "function") then
                label.optionIndex()
            end
        else

            TashDialogueLog:OnCloseChatter()

            self:CloseChatter()
        end
    end
end