local A=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local v=A:WaitForChild("\099\111\109\109\111\110")local Y=A:WaitForChild("\108\105\098")local i=require(Y:WaitForChild("\080\105\122\122\097\065\108\112\097\099\097"))local C=require(v:WaitForChild("\083\101\108\101\099\116\111\114\115"))local R=require(v:WaitForChild("\065\099\116\105\111\110\115"))local M=1500 local k=i.GameModule:extend("\076\111\103\105\110\066\111\110\117\115")local function H(A,v)local Y=os.date("\033\042\116")local i=C.getLastLogin(A,v)if not i then return true end local R=os.date("\033\042\116",i)if Y.day~=R.day then return true end end function k.onStore(v,A)local Y=v.core:getModule("\080\108\097\121\101\114\072\097\110\100\108\101\114")Y.playerLoaded:connect(function(v)wait(5)local Y=A:getState()local i=H(Y,v)if i then A:dispatch(R.COIN_ADD(v,M))A:dispatch(R.CANDY_ADD(v,250))end A:dispatch(R.LASTLOGIN_SET(v,os.time()))end)end function k.postInit(A)local v=A.core:getModule("\083\116\111\114\101\067\111\110\116\097\105\110\101\114");(v:getStore()):andThen(function(v)A:onStore(v)end)end return k
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local common = ReplicatedStorage:WaitForChild("common")
local lib = ReplicatedStorage:WaitForChild("lib")

local PizzaAlpaca = require(lib:WaitForChild("PizzaAlpaca"))
local Selectors = require(common:WaitForChild("Selectors"))
local Actions = require(common:WaitForChild("Actions"))

local DAILY_LOGIN_BONUS = 1500

local LoginBonus = PizzaAlpaca.GameModule:extend("LoginBonus")

local function shouldAwardBonus(state,player)
    local nowDate = os.date("!*t")
    local lastLoginSecs = Selectors.getLastLogin(state,player)
    if not lastLoginSecs then return true end -- must be first join
    local lastLoginDate = os.date("!*t",lastLoginSecs)

    if nowDate.day ~= lastLoginDate.day then
        return true
    end
end

function LoginBonus:onStore(store)
    local playerHandler = self.core:getModule("PlayerHandler")

    playerHandler.playerLoaded:connect(function(player)
        wait(5)
        local state = store:getState()
        local shouldAward = shouldAwardBonus(state,player)
        if shouldAward then
            store:dispatch(Actions.COIN_ADD(player,DAILY_LOGIN_BONUS))
            store:dispatch(Actions.CANDY_ADD(player,250))
            -- TODO: thank the player for joining with a login award modal
        end

        store:dispatch(Actions.LASTLOGIN_SET(player,os.time()))
    end)
end

function LoginBonus:postInit()
    local storeContainer = self.core:getModule("StoreContainer")

    storeContainer:getStore():andThen(function(newStore)
        self:onStore(newStore)
    end)
end

return LoginBonus