How do I make global switch toggle for dark mode which is both manual and also follows the system dark mode?

Basically , I want to make a toggle through which I can manually control the dark mode color of my theme , but it also automatically turns on and off based on the dark mode of my system .