import {api} from "./api";
import {requests} from "../../requests";
import {getComparator} from "../../components/core/getComparator";

class CategoryClient {

    getCategoryList(setCategory, createError) {
        api().get(requests.category.basic)
            .then((r) => {
                setCategory(r.data.sort(getComparator())
                    .map((item, i) => {
                        return {id: i, name: item}
                    }))
            })
            .catch(() => createError("Ошибка получения категорий"))
    }
};

export const categoryClient = new CategoryClient();