import Babolygologo from "@/Components/BabolygoLogo";
import Dropdown from "@/Components/Dropdown";
import NavLink from "@/Components/NavLink";
import ResponsiveNavLink from "@/Components/ResponsiveNavLink";
import {Link} from "@inertiajs/react";
import {PropsWithChildren, useState} from "react";
import {IUser} from "@/types";

export default function NavbarUser({
                                       user,
                                   }: PropsWithChildren<{ user: IUser }>) {
    const [showingNavigationDropdown, setShowingNavigationDropdown] =
        useState(false);

    return (
        <div>
            <nav className="">
                <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 ">
                    <div className="flex justify-between h-16 ">
                        <div className="flex ">
                            <div className="shrink-0 flex items-start">
                                <Link href={route("dashboard")}>
                                    <Babolygologo className="block w-auto fill-current"/>
                                </Link>
                            </div>
                        </div>
                        <div className="flex bg-babolygo-pink rounded-full m-2">
                            <div className="hidden space-x-8 sm:-my-px sm:ms-10 sm:me-10 sm:flex  ">
                                <NavLink
                                    href={route("dashboard")}
                                    active={route().current("dashboard")}
                                >
                                    Kezdőlap
                                </NavLink>
                                <NavLink
                                    href={route("meals.index")}
                                    active={route().current("meals.index")}
                                >
                                    Heti étlap
                                </NavLink>
                                <NavLink
                                    href={route("cancellations.index")}
                                    active={route().current("cancellations.index")}
                                >
                                    Lemondás
                                </NavLink>
                                <NavLink
                                    href={route("invoices.index")}
                                    active={route().current("invoices.index")}
                                >
                                    Fizetés
                                </NavLink>
                                <NavLink
                                    href={route("contact.index")}
                                    active={route().current("contact.index")}
                                >
                                    Kapcsolatok
                                </NavLink>
                            </div>
                        </div>

                        <div className="hidden sm:flex sm:items-center sm:ms-6">
                            <div className="ms-3 relative">
                                <Dropdown>
                                    <Dropdown.Trigger>
                                        <span className="inline-flex rounded-md">
                                            <button
                                                type="button"
                                                className="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-white  bg-babolygo-purple  hover:text-gray-200  focus:outline-none transition ease-in-out duration-150"
                                            >
                                                {user.full_name}

                                                <svg
                                                    className="ms-2 -me-0.5 h-4 w-4"
                                                    xmlns="http://www.w3.org/2000/svg"
                                                    viewBox="0 0 20 20"
                                                    fill="currentColor"
                                                >
                                                    <path
                                                        fillRule="evenodd"
                                                        d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
                                                        clipRule="evenodd"
                                                    />
                                                </svg>
                                            </button>
                                        </span>
                                    </Dropdown.Trigger>

                                    <Dropdown.Content>
                                        <Dropdown.Link
                                            href={route("profile.edit")}
                                        >
                                            Fiókadatok kezelése
                                        </Dropdown.Link>
                                        <Dropdown.Link
                                            href={route("logout")}
                                            method="post"
                                            as="button"
                                        >
                                            Kijelentkezés
                                        </Dropdown.Link>
                                    </Dropdown.Content>
                                </Dropdown>
                            </div>
                        </div>

                        <div className="-me-2 flex items-center sm:hidden">
                            <button
                                onClick={() =>
                                    setShowingNavigationDropdown(
                                        (previousState) => !previousState
                                    )
                                }
                                className="inline-flex items-center justify-center p-2 rounded-md text-babolygo-purple  hover:bg-white  focus:outline-none focus:bg-white   transition duration-150 ease-in-out"
                            >
                                <svg
                                    className="h-6 w-6"
                                    stroke="currentColor"
                                    fill="none"
                                    viewBox="0 0 24 24"
                                >
                                    <path
                                        className={
                                            !showingNavigationDropdown
                                                ? "inline-flex"
                                                : "hidden"
                                        }
                                        strokeLinecap="round"
                                        strokeLinejoin="round"
                                        strokeWidth="2"
                                        d="M4 6h16M4 12h16M4 18h16"
                                    />
                                    <path
                                        className={
                                            showingNavigationDropdown
                                                ? "inline-flex"
                                                : "hidden"
                                        }
                                        strokeLinecap="round"
                                        strokeLinejoin="round"
                                        strokeWidth="2"
                                        d="M6 18L18 6M6 6l12 12"
                                    />
                                </svg>
                            </button>
                        </div>
                    </div>
                </div>

                <div
                    className={
                        (showingNavigationDropdown ? "block" : "hidden") +
                        " sm:hidden bg-babolygo-purple "
                    }
                >
                    <div className="pt-2 pb-3 space-y-1 ">
                        <ResponsiveNavLink
                            href={route("dashboard")}
                            active={route().current("dashboard")}
                        >
                            Kezdőlap
                        </ResponsiveNavLink>
                    </div>
                    <div className="pt-2 pb-3 space-y-1">
                        <ResponsiveNavLink
                            href={route("meals.index")}
                            active={route().current("meals.index")}
                        >
                            Heti étlap
                        </ResponsiveNavLink>
                    </div>
                    <div className="pt-2 pb-3 space-y-1">
                        <ResponsiveNavLink
                            href={route("cancellations.index")}
                            active={route().current("cancellations.index")}
                        >
                            Lemondás
                        </ResponsiveNavLink>
                    </div>
                    <div className="pt-2 pb-3 space-y-1">
                        <ResponsiveNavLink
                            href={route("invoices.index")}
                            active={route().current("invoices.index")}
                        >
                            Fizetés
                        </ResponsiveNavLink>
                    </div>
                    <div className="pt-2 pb-3 space-y-1">
                        <ResponsiveNavLink
                            href={route("contact.index")}
                            active={route().current("contact.index")}
                        >
                            Kapcsolatok
                        </ResponsiveNavLink>
                    </div>

                    <div className="pt-4 pb-1 border-t text-center">
                        <div className="px-4">
                            <div className="font-extrabold   text-base text-white ">
                                {user.full_name}
                            </div>
                        </div>

                        <div className="mt-3 space-y-1 ">
                            <ResponsiveNavLink href={route("profile.edit")}>
                                Fiókadatok kezelése
                            </ResponsiveNavLink>
                            <ResponsiveNavLink
                                method="post"
                                href={route("logout")}
                                as="button"
                            >
                                Kijelentkezés
                            </ResponsiveNavLink>
                        </div>
                    </div>
                </div>
            </nav>
        </div>
    );
}
