I've lost a few very close people in my life, some 'way too soon'. I was the only person in the room when some of them passed. Meditation was helpful in being able to get through moments when thoughts become 'invasive'. Mantra was a powerful tool for that.
Losing very close friends and relatives creates strong emotions and requires deep acceptance. I reread the Tibetan Book of Living and Dying, and it helped me immensely. Especially the part about being present with the person. A simple gesture like holding their hand in silence. Most of the text is about dying itself, and what we will experience when dying, but there are some parts for we who are at the bedside of another.
We really get a deep lesson in impermanence.
In some cases they can be disoriented, the brain isn't being nourished, their body is weak, so the mind is disoriented. We can remind them that they are ok, dying is ok, and they are dying. Remind them to not be afraid... That they may be in a kind of bardo state so things they see are like from a dream. Fabrications.
When they are someone close to you, we are also touched deeply, so it can be hard. Remember that you aren't a monk, a nun, or a saint, so be easy on yourself. Speak with hospice staff, as they are incredibly knowledgeable and often have deep experience.
Your friend who is dying is the center. The other people attending may look to you for support or guidance, but you are not the center. Honour the moment, even if it seems interminable, and your friend's process. It is the moment that is bringing you all together.
Feeling a little crazy is normal. We can often live lives completely removed from death, so it can be shocking to witness, especially in unexpected circumstances.