The idea of surprising her suddenly flashed through my mind.

Literal

Her surprise idea [subject-が] suddenly my head [in-に] flashed.

ひらめいた means 'flashed, came to mind.' 驚かせようという考え is a complex noun phrase: 'the idea of trying to surprise her.'