sudoku = require "sudoku"
uiUtils = require "ui.utils"
config = require "config"
SudokuCanvas = require "ui.sudokucanvas"

board = {}

function love.load()
    love.window.setTitle("Sudoku!")
    love.window.fullscreen = true

    love.window.setMode(0, 0)
    love.mouse.setGrabbed(false)
    love.keyboard.setKeyRepeat(true)
    math.randomseed(os.time())
    board = sudoku.loadBoard(config.board.filePath)
    -- local width, height = love.graphics.getDimensions()
    local width, height = love.window.getDesktopDimensions()
    love.window.setMode(width, height, {fullscreen = true})
    sudokuCanvas = SudokuCanvas:new(500, 50, height/1.1, config.SudokuCanvas)
    sudokuCanvas:setBoard(board[1])
    myFont = love.graphics.newFont(24)
end

function love.draw()
    uiUtils.setBackgroundColor(config.window.bgColor)
    sudokuCanvas:draw()
end

function love.keypressed(key)
    sudokuCanvas:keypressed(key)
    local shift = love.keyboard.isDown('rshift') or love.keyboard.isDown('lshift')
    if key == "escape" or key == "q" then
        love.event.quit()
    end
end

function love.mousepressed(x, y, button, istouch)
    sudokuCanvas:mousepressed(x, y, button)
end
