How does Invisibility work if you cast it while observed?

In PF2, undetected and hidden are distinct conditions. A literal reading of the invisibility spell suggests that, upon casting the spell, the caster automatically becomes undetected.

Cloaked in illusion, the target becomes invisible. This makes it undetected to all creatures, though the creatures can attempt to find the target, making it hidden to them instead.

If the caster is undetected, then other creatures can attempt to find them by taking the seek action on their turns.

However, the rules for being invisible seem to contradict this:

If you become invisible while someone can already see you, you start out hidden to the observer (instead of undetected) until you successfully Sneak.

Suppose a spellcaster is being observed, and they cast invisibility. Do they become undetected, or do they become hidden?

If they want to become undetected, would they need to use an action to Sneak after turning invisible?