local DayComp = class("DayComp", LuaComponent)

-- dataInfo = {{over = bool, rp = bool, func = function(day) end}, {}}
function DayComp:refresh(parentUI, dataInfo, selectedDay, maxShowDay, period)
    local uiMap = self:getUIMap()
    if not self.chooseBgs then
        self.touchs = {}
        self.chooseBgs = {}
        self.dayDescs = {}
        self.dayChooseDescs = {}
        self.rpPoints = {}
        self.checks = {}
        self.locks = {}
        for i = 1, 7 do
            local prefix = "r_menu.r_menu_" .. i
            self.touchs[i] = uiMap[prefix]
            self.chooseBgs[i] = uiMap[prefix .. ".r_menu_choose"]
            self.dayDescs[i] = uiMap[prefix .. ".day_tx"]
            self.dayChooseDescs[i] = uiMap[prefix .. ".day_tx_choose"]
            self.rpPoints[i] = uiMap[prefix .. ".point_img"]
            self.checks[i] = uiMap[prefix .. ".check_img"]
            self.locks[i] = uiMap[prefix .. ".lock"]
        end
    end

    for day, obj in ipairs(self.touchs) do
        obj:addClickListener(function()
            if day > maxShowDay then
                return
            end

            if dataInfo[day].func then
                dataInfo[day].func(day)
            end
            self:refresh(parentUI, dataInfo, day, maxShowDay)
        end)
        self.locks[day]:setVisible(day > maxShowDay)
        self.chooseBgs[day]:setVisible(selectedDay == day)
        if dataInfo[day] and dataInfo[day].over then
            self.dayDescs[day]:setText(GConst.EMPTY_STRING)
            self.dayChooseDescs[day]:setText(GConst.EMPTY_STRING)
            self.checks[day]:setVisible(true)
            self.rpPoints[day]:setVisible(false)
        else
            if selectedDay == day then
                self.dayDescs[day]:setText(GConst.EMPTY_STRING)
                self.dayChooseDescs[day]:setText(day)
            else
                self.dayDescs[day]:setText(day)
                self.dayChooseDescs[day]:setText(GConst.EMPTY_STRING)
            end
            self.checks[day]:setVisible(false)
            if dataInfo[day] and dataInfo[day].rp then
                self.rpPoints[day]:setVisible(true)
            else
                self.rpPoints[day]:setVisible(false)
            end
        end
    end
end

return DayComp