
local nameField = nil
NameInput.open = false

----------------------------------------------------------------------------------------------------
function NameInput_INIT()

    NameInput:get_element("newProfile"):setVisible(false)
    nameField = EditTextElem:new(NameInput:get_element('input_field'),
        {filter = {92, 47, 58, 42, 63, 60, 62, 124, 32}, max_length = 12, enterCall = enterCallback})

    NameInput:set_visible(false)
    NameInput:set_active(false)
end

----------------------------------------------------------------------------------------------------
function NameInput_UPDATE()
	return 0
end

----------------------------------------------------------------------------------------------------
function NameInput:onShow()
end


----------------------------------------------------------------------------------------------------
function NameInput:onHide()
end

function enterCallback()
    if nameField:getText() == '' then
        nameField:notify('ids_empty_name')
        return
    end

    if NameInput.callback ~= nil then
        local message = NameInput.callback(nameField:getText())
        if message ~= nil then
            nameField:notify(message)
            return
        end
    end

    NameInput:hide()
end

----------------------------------------------------------------------------------------------------
function NameInput:show(callback)
    NameInput:set_visible(true)
    NameInput:set_active(true)

    NameInput.open = true

    NameInput.callback = callback
    NameInput:set_element_eh('btn_yes_view', enterCallback)

    NameInput:get_element("newProfile"):setVisible(true)
    addInputListener(nameField)
    nameField:reset()

end

----------------------------------------------------------------------------------------------------
function NameInput:hide()
    NameInput.open = false

    removeInputListener(nameField)
    NameInput:get_element("newProfile"):setVisible(false)

    NameInput:set_visible(false)
    NameInput:set_active(false)

end

