Renaming Long Filenames And Keeping Details

I have a tricky rename that i need to create a script for but the scripting is a little over my head.

I need to rename files that are very long to be under 30 characters but are suffixed like this:

big old lonnnnnnngggggggggg filename -category1.txt
to

big old lonnnnnnngggggggggg f -category1.txt

I want it to truncate after 30 characters and add on the -category1 then add the extension. Note there can also be a -category2 as well.

Is this possible and how would i tackle it?

thx.

So you want to keep everything after the first space, minus sequence, and truncate everything before that to 30 characters max?

What happens if there isn't any category? Skip the file? Or truncate everything up to the extension?