local entity = require("entity")
local window = require("window")
local seed = require("item/seed")

local pot = {
    {'fill', {60, 80, 100, 80, 100, 90, 60, 90}},
    {'fill', {65, 90, 95, 90, 90, 120, 70, 120}},
    {'line', {80, 80, 70, 60, 60, 50}},
    {'line', {70, 60, 80, 50}},
}

local m = entity:from{
    width = 120,
    height = 120,
    grown = false,
}

function m:update()
end

m.draw = window.draw(function (self)
    self:draw_lines(pot)

    if grown then
        love.graphics.circle('fill', 80, 50, 5)
        for i = 0, 7 do
            local x = 80 + 7 * math.sin(math.pi * i)
            local y = 50 + 7 * math.cos(math.pi * i)
            love.graphics.line(80, 50, x, y)
        end
    end
end)

m.mousepressed = window.mousepressed(function (self, x, y, button)
    local i = inventory.selected_item

    if i and i.name == "Flask" then
        inventory:use()
        local seed = seed:from{ colour = i.colour }
        self.grown = true
        seed:install(self.room, self.width + 80, self.height + 50)
    end
end)

return m