#include "win.h"
#include "other/log.h"
#include "mini/file/file.h"
#include "mini/shader/shader.h"
#include "backends/backend.h"

#include <stdlib.h>

namespace mini
{
    namespace win
    {
        state_t state;

        void init() {
            backend::video::init();
            log_msg(LOG_OK, "Graphics subsystem initialized\n");
        }

        void quit() {
            backend::video::quit();
        }

        void raise() {
            backend::video::raise_window();
        }

        namespace zoom {
            int get() {
                return state.zoom;
            }
            void set(const int value) {
                state.zoom = value;
                quit();
                init();
                file::setconfigvalue("zoom", std::to_string(state.zoom).c_str());
            }
        }

        namespace fullscreen {
            bool get() {
                return state.fullscreen;
            }
            void set(const bool value) {
                state.fullscreen=value;
                quit();
                init();
                file::setconfigvalue("fullscreen", state.fullscreen?"true":"false");
            }
        }

        namespace cursor {
            bool get() {
                return state.cursor;
            }
            void set(const bool value) {
                state.cursor=value;
                backend::video::cursor(value);
            }
        }

        namespace res {
            void set(const int w, const int h) {
                state.width = w;
                state.height = h;
                quit();
                init();
            }
            int getw() { return state.width; }
            int geth() { return state.height; }
        }
    }
}