-- GoTo("s04_0118_queen_memoir")

local scroll_content = {
  { left  = {"doc_diary_01"}, bg = "page_1" }, 
}

local CurrentPage = 1 

function OnCreate()
  SetDiaryPage(CurrentPage)
end

function OnShow()
  UpdateArrowsVisible()
end

function OnHide()
  
end

function OnMouseEnter(_sender) SetInterfaceCaption(L10n:ExpandString(_sender:GetCaption())) end
function OnMouseLeave(_sender) SetInterfaceCaption("") end

function  OnNextPage()
  if CurrentPage + 1 > #scroll_content then return end
  CurrentPage = CurrentPage + 1
  SetDiaryPage(CurrentPage)
  UpdateArrowsVisible()
end

function  OnPrevPage()
  if CurrentPage == 1 then return end
  CurrentPage = CurrentPage - 1
  SetDiaryPage(CurrentPage)
  UpdateArrowsVisible()
end

function UpdateArrowsVisible()
  self:FindChild("PrevPage"):SetVisible( CurrentPage > 1 )
  self:FindChild("NextPage"):SetVisible( CurrentPage < #scroll_content )  
end

function SetDiaryPage(p)
 
 local function setText(txt, name, t)
    local textSet = DiaryPages[t][name]
    local text = ""
    if textSet ~= nil then
      for i = 1,#textSet do text = text.."\n\t"..L10n:ExpandString(textSet[i]) end
      txt:SetText(text)
      txt:SetVisible(true)
    else
      txt:SetVisible(false)
    end
  end
 
  local img   = self:FindChild("Diary_")
  local left  = self:FindChild("DiaryLeftPage")
  local right = self:FindChild("DiaryRightPage")
  
  setText(left, "left", p)
  setText(right, "right", p)
  
  if scroll_content[p]["bg"] ~= nil then 
    img:SetSkin(scroll_content[p]["bg"])
  else
    img:SetSkin("makeda_scroll_page_empty")
  end
  UpdateArrowsVisible()
end

function SetDiaryTextAlign()
  local left  = self:FindChild("DiaryLeftPage")
  local right = self:FindChild("DiaryRightPage")
  
  if scroll_content[CurrentPage][3] == nil or scroll_content[CurrentPage][3] == "left" then
    left:SetVisible(true)
    right:SetVisible(false)
    return left
  else
    right:SetVisible(true)
    left:SetVisible(false)
    return right
  end  
end

