local this = class("pageCommonTextBox", G_UIPageBase)

function this.bind()
  return {
    module_commonTipSmall = L_Const.ModuleInfo.CommonTipSmall,
    txt_tip = nil,
    txt_renamePlaceHolder = nil,
    txt_renameContent = nil,
    txt_signaturePlaceHolder = nil,
    txt_signatureContent = nil,
    active_txt_rename = false,
    active_txt_signature = false,
    sortingOrder_page = nil
  }
end

function this.methods()
  return {
    module_commonTipSmall = {
      onClick_close = function(self)
        if self._params.closeCallbackTemp then
          self._params.closeCallbackTemp()
        end
        L_UI:close(self.pageName)
      end,
      onClick_cancel = function(self)
        if self._params.cancelCallback then
          self._params.cancelCallback()
        end
        L_UI:close(self.pageName)
      end,
      onClick_confirm = function(self)
        if self._params.confirmCallback then
          local txt
          if self._params.textBoxType == L_Const.CommonTextBoxType.Rename then
            txt = self.bindComponents.Input_text_rename.text
          elseif self._params.textBoxType == L_Const.CommonTextBoxType.Signature then
            txt = self.bindComponents.Input_text_signature.text
          end
          self._params.confirmCallback(txt)
          if not self.keepPageOpen then
            L_UI:close(self.pageName)
          end
        end
      end,
      onClick_bg = function(self)
        L_UI:close(self.pageName)
      end
    },
    onValueChanged_renameInput = function(self, value)
      if not self.limit or self.limit <= 0 then
        return
      end
      if C_LuaUtility.StringLength(value) > self.limit then
        self.bindComponents.Input_text_rename.text = C_LuaUtility.StringSub(value, 0, self.limit)
      end
    end,
    onValueChanged_signatureInput = function(self, value)
      if not self.limit or self.limit <= 0 then
        return
      end
      if C_LuaUtility.StringLength(value) > self.limit then
        self.bindComponents.Input_text_signature.text = C_LuaUtility.StringSub(value, 0, self.limit)
      end
    end
  }
end

function this:preOpen(options)
  this.super.preOpen(self, options)
  self:refreshPage(options)
end

function this:refreshPage(params)
  self._params = params or {}
  self.modules.module_commonTipSmall:initModule(params)
  if params.textBoxType == L_Const.CommonTextBoxType.Rename then
    self.bind.active_txt_rename = true
    self.bind.txt_renamePlaceHolder = params.placeHolder
    self.bind.txt_renameContent = params.txtContent
    self.bind.txt_tip = params.tip or ""
  elseif params.textBoxType == L_Const.CommonTextBoxType.Signature then
    self.bind.active_txt_signature = true
    self.bind.txt_signaturePlaceHolder = params.placeHolder
    self.bind.txt_signatureContent = params.txtContent
  end
  self.limit = params.limit and params.limit * 2 or 0
  self.keepPageOpen = params.keepPageOpen
  if not math.isEmpty(params.overrideSortingOrder) then
    self.bind.sortingOrder_page = params.overrideSortingOrder
  end
end

function this:close()
  this.super.close(self)
  if self._params.pageClosedCallback then
    self._params.pageClosedCallback()
  end
end

function this:escHandle()
  if self._params.closeCallbackTemp then
    self._params.closeCallbackTemp()
  end
end

return this
