local this = L_BevTree:registClass("guide.checkOpenWindow", L_BevTree.action)

function this:param()
  self.windowName = ""
  self.isReverse = 0
end

function this:parse()
  self.windowName = self:getParam("windowName")
  local isReverse = self:getParam("isReverse", true) or 0
  self.isReverse = isReverse ~= 0
end

function this:onEnter()
  if self.isReverse then
    L_UI:addListener(L_UI.pageEvent.showed, self.onPageShowed, self)
  end
  self.result = L_BevTree.taskResult.Running
end

function this:onPageShowed(pageName)
  if self.isReverse and pageName ~= self.windowName then
    self.result = L_BevTree.taskResult.Success
  end
end

function this:onDestroy()
  if self.isReverse then
    L_UI:removeListener(L_UI.pageEvent.showed, self.onUIOpen, self)
  end
end

function this:onFinish()
  if self.isReverse then
    L_UI:removeListener(L_UI.pageEvent.showed, self.onUIOpen, self)
  end
end

function this:execute()
  if not self.isReverse and L_GuideManager:checkPageOpen(self.windowName) then
    self.result = L_BevTree.taskResult.Success
  end
  return self.result
end

return this
