import DataUtils, {
    REQUEST_TYPE_GET,
    REQUEST_TYPE_PUT,
    REQUEST_TYPE_POST,
    REQUEST_TYPE_DELETE,
    CONTENT_TYPE_JSON,
    CONTENT_TYPE_FORM
} from '../tools/utilities/DataUtils.jsx';
import * as DataEvent from '../tools/events/DataEvent.jsx';
import StringUtils from '../tools/utilities/StringUtils.jsx';
class TaskFipamo {
    //--------------------------
    // constructor
    //--------------------------
    constructor() {
        var folio = [];
        this.dataUtils = new DataUtils();
    }
    //--------------------------
    // methods
    //--------------------------
    start() {}

    submitLink(edit) {
        let self = this;
        return new Promise(function (resolve, reject) {
            let link_data = '';
            let postURL;
            let postEventType;
            console.log('EDIT: '+edit);
            if (edit) {

                //TODO: FIX TAGS,NEEDS TO BE SUBMITTED AS AN ARRAY

                link_data = {
                    "title": document.getElementById('saved_title').value,
                    "tags": document.getElementById('saved_tags').value,
                    "image": document.getElementById('saved_image').value 
                };
                let savedID = document.getElementById('saved-sumbit-btn').getAttribute('data-id');
                postURL = "/api/bookmarks/update/" + savedID;
                postEventType = DataEvent.LINK_UPDATED;
                console.log('url'+postURL);
            } else {
                link_data = {
                    "url": document.getElementById('saved_text').value
                };

                postURL = "/api/bookmarks/add";
                postEventType = DataEvent.LINK_ADDED;
            }
            console.log('POSTING');
            self.dataUtils.request(postURL, postEventType, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, link_data)
                .then((response) => {
                    resolve({
                        response
                    })
                }).catch((err) => {
                    reject({
                        err
                    });
                })
        });
    }
    //--------------------------
    // event handlers
    //--------------------------
}
export {
    TaskFipamo as
    default
}
