"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
const react_router_dom_1 = require("react-router-dom");
const useRelativePathData = () => {
    const { resourceRoot } = (0, react_router_dom_1.useParams)();
    const { url: matchUrl } = (0, react_router_dom_1.useRouteMatch)();
    const { pathname, search } = (0, react_router_dom_1.useLocation)();
    const relativePath = (0, react_1.useMemo)(() => {
        return pathname.slice(pathname.indexOf(matchUrl) + matchUrl.length).replace(/^\//, '');
    }, [pathname, matchUrl]);
    const relativePathBreadCrumb = (0, react_1.useMemo)(() => {
        return `${relativePath || ''}`
            .split('/')
            .filter(Boolean)
            .reduce((arr, name) => {
            arr.push({
                name,
                link: `${arr[arr.length - 1].link}/${name}`,
            });
            return arr;
        }, [
            {
                name: resourceRoot,
                link: `/#${matchUrl}${search}`,
            },
        ]);
    }, [relativePath]);
    return {
        folderPath: `${resourceRoot}${relativePath ? '/' : ''}${relativePath || ''}`,
        relativePath,
        relativePathBreadCrumb,
    };
};
exports.default = useRelativePathData;
