local AccountDeleteUI = class("AccountDeleteUI", BaseUI)

function AccountDeleteUI:isFullScreen()
    return false
end

function AccountDeleteUI:showCommonBG()
    return false
end

function AccountDeleteUI:getPrefabPath()
    return "assets/prefabs/ui/setting/account_delete_ui.prefab"
end

function AccountDeleteUI:onClose()
    if self.inputFieldObj then
        self.inputFieldObj:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TMP_INPUT_FIELD).text = GConst.EMPTY_STRING
    end
end

function AccountDeleteUI:ctor(params)
    self.besureTxStr = I18N:getGlobalText(I18N.GlobalConst.BESURE_DELETE_ACCOUNT_DESC)
    self.hideCloseBtn = params and params.hideCloseBtn
end

function AccountDeleteUI:onLoadRootComplete()
    local uiMap = self.root:genAllChildren()
    self.okBtn = uiMap["account_delete_ui.title_bg_img.change_btn"]
    self.btnTx = uiMap["account_delete_ui.title_bg_img.change_btn.text"]
    self.okBtnGray = uiMap["account_delete_ui.title_bg_img.change_btn.gray"]
	self.inputFieldObj = uiMap["account_delete_ui.title_bg_img.input_field"]

	self.okBtn:addClickListener(function()
        local content = self.inputFieldObj:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TMP_INPUT_FIELD).text
        if content == self.besureTxStr then
            ModuleManager.AccountManager:deleteAccount()
        end
    end)

    local closeBtn = uiMap["account_delete_ui.title_bg_img.close_btn"]
	closeBtn:addClickListener(function()
        self:closeUI()
    end)
    closeBtn:setActive(not self.hideCloseBtn)

    self:_display()
end

function AccountDeleteUI:_display()
    local uiMap = self.root:genAllChildren()
    uiMap["account_delete_ui.title_bg_img.title_text"]:setText(I18N:getGlobalText(I18N.GlobalConst.MESSAGE_BOX_TITLE))
    uiMap["account_delete_ui.title_bg_img.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.BESURE_DELETE_TIPS_DESC, self.besureTxStr))

    self:refreshBtn(true)
    self.inputFieldObj:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TMP_INPUT_FIELD).onValueChanged:AddListener(function(content)
        self:refreshBtn(content ~= self.besureTxStr)
    end)
end

function AccountDeleteUI:refreshBtn(gray)
    self.okBtnGray:setVisible(gray)
    self.okBtn:setTouchEnable(not gray)
	self.btnTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_OK))
end

return AccountDeleteUI