---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by chenzhen.
--- DateTime: 2019-08-06 20:36
---

local _class = {}
_class._name = 'PlaceholderPagerView'
_class._version = '1.0'

function _class:new(o)
    o = o or {}
    setmetatable(o, self)
    self.__index = self


    return o
end


--Public Method
function _class:rootView()
    self:configPagerView()
    return self.containerView
end

--- Private Method
function _class:configPagerView()

    self:configDataSource()
    self:configContainerView()

    --Setup TabBarSegment
    local tabSegmentPositionY = 0
    local tabSegmentHeight = 50
    local titles = Array()
    titles:add("占位页")
    self:configTabSegmentView(0, tabSegmentPositionY, window:width(), tabSegmentHeight, titles)

    self:configViewPagerAdapter()

    local viewPagerMarginTop = tabSegmentPositionY + tabSegmentHeight
    self:configViewPager(viewPagerMarginTop)
end

function _class:configDataSource()
    local placeholerDataSource = {Color(67,52,27,1)}
    self.dataSource = placeholerDataSource
end

function _class:configContainerView()
    local focusContainerView = View()
    focusContainerView
            :width(MeasurementType.MATCH_PARENT):height(MeasurementType.MATCH_PARENT):marginTop(0)
    self.containerView = focusContainerView
end

function _class:configTabSegmentView(rectX, rectY, width, height, titles)
    tabSegment = TabSegmentView(Rect(rectX, rectY, width, height),titles,Color(0,0,0,1.0)):selectScale(1.0):width(MeasurementType.MATCH_PARENT):setAlignment(TabSegmentAlignment.CENTER):setGravity(Gravity.CENTER_HORIZONTAL)
    tabSegment:setAlignment(TabSegmentAlignment.CENTER)

    self.tabSegment = tabSegment;

    --self.tabSegment:normalFontSize(18)
    self.tabSegment:setItemTabClickListener(function(index)
        print("Click",index)

    end)

    self.containerView:addView(self.tabSegment)
end

function _class:configViewPagerAdapter()
    adapter = ViewPagerAdapter()
    adapter:getCount(function(section)
        return #self.dataSource
    end)

    adapter:initCell(function(cell,row)
        local contentView = cell.contentView
    end)
    adapter:fillCellData(function(cell,row)
        local contentView = cell.contentView
        local width = contentView:width()
        local height = contentView:height()
        contentView:bgColor(self.dataSource[row])
    end)
    self.adapter = adapter
end

function _class:configViewPager(viewPagerMarginTop)
    -- Setup ViewPager
    viewPager = ViewPager()
    viewPager:scrollToPage(1,false)

    viewPager:endDragging(function(row)
        print('停止滚动了----',row)
    end)

    viewPager:marginTop(viewPagerMarginTop):width(MeasurementType.MATCH_PARENT):height(MeasurementType.MATCH_PARENT):setGravity(Gravity.CENTER_HORIZONTAL)
    viewPager:showIndicator(false)
    viewPager:adapter(self.adapter)
    self.viewPager = viewPager

    self.tabSegment:relatedToViewPager(self.viewPager,true)

    self.containerView:addView(self.viewPager)
end

return _class