import React from "react";
import {FileIcon} from "react-file-icon";

export const getFileExt = (fileName: string | undefined) => {
    const n = fileName?.match(/\.([^.]+)$/);

    return n && n[1] as string;
};

export const getFileExtIcon = (ext: string | undefined | null) => {
    switch (ext) {
    case "jpg":
    case "png":
    case "svg":
    case "gif":
    case "ico":
    case "tiff":
    case "webp":
        return React.createElement(FileIcon, {
            extension: ext,
            type: "image",
            color: "#aae1f5",
            labelColor: "#008cff",
            labelUppercase: true,
            glyphColor: "#008cff",
        });
    case "mp4":
    case "webm":
    case "mov":
    case "wmv":
    case "avi":
        return React.createElement(FileIcon, {
            extension: ext,
            type: "video",
            color: "#eccfbc",
            labelColor: "#d7711d",
            labelUppercase: true,
            glyphColor: "#d7711d",
        });
    case "mp3":
    case "wav":
    case "ogg":
        return React.createElement(FileIcon, {
            extension: ext,
            type: "audio",
            color: "#f3cfeb",
            labelColor: "#d12371",
            labelUppercase: true,
            glyphColor: "#d12371",
        });
    case "pdf":
        return React.createElement(FileIcon, {
            extension: ext,
            type: "document",
            color: "#f6e5e1",
            labelColor: "#D14423",
            labelUppercase: true,
            glyphColor: "rgba(0,0,0,0.4)",
        });
    case "csv":
    case "xls":
    case "xlsx":
    case "xml":
        return React.createElement(FileIcon, {
            extension: ext,
            type: "document",
            color: "#7bc052",
            labelColor: "#2f521c",
            labelUppercase: true,
            glyphColor: "rgba(255,255,255,0.4)",
        });
    case "pem":
    case "ppt":
    case "odp":
        return React.createElement(FileIcon, {
            extension: ext,
            type: "presentation",
            color: "#D14423",
            labelColor: "#D14423",
            labelUppercase: true,
            glyphColor: "rgba(255,255,255,0.4)",
        });
    case "apk":
        return React.createElement(FileIcon, {
            extension: ext,
            type: "binary",
            color: "#8f60d7",
            labelColor: "#65439a",
            labelUppercase: true,
            glyphColor: "rgba(255,255,255,0.4)",
        });
    case "doc":
    case "docx":
    case "odt":
    case "ods":
    case "txt":
    case "rtf":
    case "json":
        return React.createElement(FileIcon, {
            extension: ext,
            type: "document",
            color: "#ffffff",
            labelColor: "#4882cc",
            labelUppercase: true,
            glyphColor: "#444",
        });
    case "zip":
        return React.createElement(FileIcon, {
            extension: ext,
            type: "binary",
            color: "#ffffff",
            labelColor: "#641ba2",
            labelUppercase: true,
            glyphColor: "#641ba2",
        });
    default:
        return React.createElement(FileIcon, {
            type: "binary",
            labelUppercase: true,
            color: "#eacc94",
            labelColor: "#ab8d55",
        });
    }
};
