#include "../../script/helpers/entity.lua"
#include "../../config/events.lua"


function init()
    body = FindBody()
    grip = FindShape("grip")
    joint = FindJoint()
    min, max = GetJointLimits(joint)
    SetJointMotorTarget(joint, min)
end

function tick(dt)
    if disabled or not IsHandleValid(body) then return end

    if InputPressed("interact") and GetPlayerInteractBody() == body
    or IsBodyBroken(body) or IsShapeBroken(grip) then
        SetJointMotorTarget(joint, max, 0.35)
        RemoveTag(body, "interact")
        TriggerEvent(EVENTS.UPDATE_STATE, "fireworks")
        disabled = cEntity:EnqueueDeletion()
    end
end
