
export const API_BASE = '/api';

const BINDER_SORT_STORAGE_KEY = 'lorebinder_binder_sort';

const VALID_BINDER_SORTS = ['updated_desc', 'created_desc', 'created_asc', 'name_asc', 'name_desc'];

export const state = {
    currentCards: [],
    currentBinder: null,
    binderList: [],
    allTags: [],
    gravityLocked: false,
    isPasteProcessing: false,
    binderSort: VALID_BINDER_SORTS.includes(localStorage.getItem(BINDER_SORT_STORAGE_KEY))
        ? localStorage.getItem(BINDER_SORT_STORAGE_KEY)
        : 'updated_desc',
    settings: {
        allow_image_paste: false
    },
    modals: {
        resource: null,
        binder: null,
        binderLink: null,
        searchResource: null,
        bulkTag: null,
        bulkResize: null
    },
    ctxTargetId: null,
    ctxTargetCard: null,
    ctxMouseX: undefined,
    ctxMouseY: undefined
};

export function setBinderSort(sortKey) {
    if (!VALID_BINDER_SORTS.includes(sortKey)) return;
    state.binderSort = sortKey;
    localStorage.setItem(BINDER_SORT_STORAGE_KEY, sortKey);
}
