Magento has a cookie Notice template, how to add this functionality to popup.
/vendor/magento/module-cookie/view/frontend/templates/html/notices.phtml
I found such an example of popup implementation, but whether it is necessary to implement all this for popup, maybe you will have an example of implementation specifically for this task.