You could replace the default Close/Cancel button on your pop-up with a new Action button, that calls a microflow, where you can create custom logic.
Edit: and like Maarten said, you can set a confirmation message on the button
Then you can set the Close action of the pop-up to that button (in the properties window of the pop-up page), so that when someone closes the pop-up with the 'x' or presses escape, the microflow behind your custom Close button is triggered.
Hi,
If you create an action/microflow button with a custom microflow you have an option to 'ask confirmation' within the microflow settings.
With this option you can create a warning message.