import {writable } from 'svelte/store';

const createFiles = function(files) {
    const { subscribe, set, update } = writable(files);
    return {
        subscribe,
        set,
        // setFiles: (newFiles) => update(files => newFiles),
        reset: () => set(files),
        pushList: (file) => {
            files.push(file);
            set(files);
        },
        setList: (files) => {
            set(files);
        }
    };
};
const storeFiles = createFiles([]);

const createDeletedFiles = function(files) {
    const { subscribe, set, update } = writable(files);
    return {
        subscribe,
        set,
        reset: () => set(files),
        pushList: (file) => {
            files.push(file);
            set(files);
        },
        setList: (files) => {
            set(files);
        }
    };
};
const storeDeletedFiles = createDeletedFiles([]);

const createNewFiles = function(files) {
    const { subscribe, set, update } = writable(files);
    return {
        subscribe,
        set,
        // setFiles: (newFiles) => update(files => newFiles),
        reset: () => set(files),
        pushList: (file) => {
            files.push(file);
            set(files);
        },
        setList: (files) => {
            set(files);
        }
    };
};
const storeNewFiles = createNewFiles([]);

const createUrlFiles = function(files) {
    const { subscribe, set, update } = writable(files);
    return {
        subscribe,
        set,
        // setFiles: (newFiles) => update(files => newFiles),
        reset: () => set(files),
        pushList: (file) => {
            files.push(file);
            set(files);
        },
        setList: (files) => {
            set(files);
        }
    };
};
const storeUrlFiles = createUrlFiles([]);

export {
    storeFiles,
    storeUrlFiles,
    storeDeletedFiles,
    storeNewFiles
};