#ifndef HEADER_VIEW_TARGET
#define HEADER_VIEW_TARGET

#include <stdlib.h>
#include "../../source/inout/XViewTarget.hpp"

USING_NS_GAODING_MEDIA

class WebViewTarget: public XViewTarget {
    public:
        bool needOffscreen() override{
            return offscrren;
        }

        void setOffscrren(bool _offscreen) {
            offscrren = _offscreen;
        }

        bool getOffscreen() {
            return offscrren;
        }

    private:
        bool offscrren = false;
};

class ViewTarget {
    public:
        ViewTarget(std::string canvasID) {
            target = std::make_shared<WebViewTarget>();
            setPlatformData(canvasID);
        }

        ~ViewTarget() {
            target.reset();
        }

        void setPlatformData(std::string canvasID) {
            const char* source = canvasID.data();
            int size = sizeof(source);
            char *platformData = (char *) malloc(size);
            strcpy(platformData, source);
            target->setPlatformData((void *) platformData);
        }

        void setTargetSize(unsigned int width, unsigned int height) {
            target->setSize({width, height});
        }

        void setOffscreen(bool offscreen) {
            target->setOffscrren(offscreen);
        }

        std::shared_ptr<WebViewTarget> getInstance() {
            return target;
        }

    protected:
        std::shared_ptr<WebViewTarget> target;
};
#endif