import router from "../router/index.js";

export const toPath = (path, query = {}) => {
    router.push({
        path: path,
        query: query
    }).then();
}

export const VITE_TINYMCE_KEY = () => {
    return import.meta.env.VITE_TINYMCE_KEY;
}

export const deleteObjectFields = (obj) => {
    Object.keys(obj).forEach(key => {
        delete obj[key];
    });
}

export const baseImage = (url) => {
    if (!url) url = '';
    return url.startsWith('http') ? url : import.meta.env.VITE_API_URL + url;
}

export const determineMediaType = (url) => {
    const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg'];
    const videoExtensions = ['.mp4', '.mov', '.avi', '.mkv', '.webm'];

    const extension = url.substring(url.lastIndexOf('.')).toLowerCase();

    if (imageExtensions.includes(extension)) {
        return 'Image';
    } else if (videoExtensions.includes(extension)) {
        return 'Video';
    } else {
        return 'Unknown';
    }
}
