<script>
    import { storePermisos } from "$/stores/global";
    import { Link, useMatch } from "svelte-navigator";

    export let to = "#";
    const absoluteMatch = useMatch(to);
    let exist = false

    storePermisos.subscribe(val => {
        exist = val.findIndex(r => r.path.indexOf(to) === 0) !== -1;
    })

    let match;
    $: match = $absoluteMatch?.fullPath === to;
</script>

{#if exist}
    <li class={"sidebar-item" + (match ? " active" : "")}>
        <Link class="sidebar-link" {to}>
            <slot />
        </Link>
    </li>
{/if}
