import React, { Children, FC } from "react";
import Link from "next/link";
import styles from './breadcrumbs.module.scss';
import clsx from 'clsx';

export type BreadcrumbsProps = {
    className?: string;
    style?: object;
};

const Breadcrumbs : FC<BreadcrumbsProps> = ({children, className, ...props}) => (
    <div className={clsx(styles.breadcrumbs, className)} {...props}>
        {Children.map(children, (child, index) => {
            return (
                <>
                    {
                        index !== 0 ? (
                            <span className={styles.divider}>/</span>
                        ) : undefined
                    }
                    {child}
                </>
            );
        })}
    </div>
);

const Crumb : FC = ({children, ...props}) => (
    <span className={styles.crumb} {...props}>
        {children}
    </span>
);

export type LinkCrumbProps = {
    href: string;
}

const LinkCrumb : FC<LinkCrumbProps> = ({children, href, ...props}) => (
    <Crumb>
        <Link href={href}>
            <a>{children}</a>
        </Link>
    </Crumb>
);

export {
    Crumb,
    Breadcrumbs,
    LinkCrumb
};