import axios from "axios";
import { createSignal } from "solid-js";


// YYYY-MM-DD to DD/MM/YYYY
export function formatDate(date: string): string {
    const [year, month, day] = date.split("-");
    return `${day}/${month}/${year}`;
}

export const backend = axios.create({
    baseURL: import.meta.env.VITE_BACKEND_URL,
});

export function wait(ms: number): Promise<void> {
    return new Promise((resolve) => setTimeout(resolve, ms));
}

export enum LoadingStatus {
    Init,
    Loading,
    Ok,
    Error,
}
export function useLoading() {
    const [status, setStatus] = createSignal(LoadingStatus.Init);
    const [error, setError] = createSignal("");

    return {error, setError, status, setStatus};
}
