"use client";

import { usePathname } from "next/navigation";
import Link from "next/link";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleLeft } from "@fortawesome/free-solid-svg-icons";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
export default function BillLayout({ children }) {
  const pathname = usePathname();
  const router = useRouter();
  const [scrollHeight, setScrollHeight] = useState(0);
  useEffect(() => {
    setScrollHeight(window.innerHeight - 44);
  }, []);
  return (
    <section className="flex flex-1 flex-col container">
      <div className="p-4 fixed top-0 z-10 w-full">
        <div className="w-9 h-9 flex items-center justify-center bg-[#FFFFFF1A] rounded-full float-left">
          <FontAwesomeIcon
            icon={faAngleLeft}
            style={{ maxWidth: "12px" }}
            size="xl"
            onClick={() => {
              router.back();
            }}
          />
        </div>
        <p className="text-base text-center leading-9">收支明细</p>
      </div>
      {pathname.split("/").length < 4 && (
        <div
          className="flex flex-col mt-14 px-4 overflow-y-auto"
          style={{ maxHeight: scrollHeight }}
        >
          <div className="tabs tab-boxed w-full py-2  sticky top-0 bg-deepBg">
            <Link
              className={`tab basis-1/4 ${
                pathname === "/bill/recharge"
                  ? "tab-active text-[#FF669E] bg-[#FF61B030] rounded-full"
                  : "text-[#FFFFFF80]"
              }`}
              href="recharge"
              replace
            >
              充值
            </Link>
            <Link
              className={`tab basis-1/4 ${
                pathname === "/bill/cost"
                  ? "tab-active text-[#FF669E] bg-[#FF61B030] rounded-full"
                  : "text-[#FFFFFF80]"
              }`}
              href="cost"
              replace
            >
              消费
            </Link>
            <Link
              className={`tab basis-1/4 ${
                pathname === "/bill/income"
                  ? "tab-active text-[#FF669E] bg-[#FF61B030] rounded-full"
                  : "text-[#FFFFFF80]"
              }`}
              href="income"
              replace
            >
              收益
            </Link>
            <Link
              className={`tab basis-1/4 ${
                pathname === "/bill/withdrawal"
                  ? "tab-active text-[#FF669E] bg-[#FF61B030] rounded-full"
                  : "text-[#FFFFFF80]"
              }`}
              href="withdrawal"
              replace
            >
              提现
            </Link>
          </div>
          <div className="flex flex-1">{children}</div>
        </div>
      )}

      {pathname.split("/").length > 3 && (
        <div className="mt-14 px-4 flex flex-1">{children}</div>
      )}
    </section>
  );
}
