"use client";
import { FC, PropsWithChildren } from "react";

interface LoadingProps {
  loading: boolean;
  text?: string;
}

const Loading: FC<PropsWithChildren<LoadingProps>> = ({
  loading,
  children,
  text = "در حال بارگذاری",
}) => {
  if (!loading) return children;

  return (
    <div
      className="flex min-h-[200px] w-full items-center justify-center"
    >
      <div className="flex flex-col items-center text-primary">
        <svg
          className="h-12 w-12 animate-spin text-primary"
          xmlns="http://www.w3.org/2000/svg"
          fill="none"
          viewBox="0 0 24 24"
          stroke="currentColor"
        >
          <circle
            className="opacity-25"
            cx="12"
            cy="12"
            r="10"
            strokeWidth="4"
            stroke="currentColor"
          />
          <path
            className="opacity-75"
            fill="currentColor"
            d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"
          />
        </svg>

        <span className="text-base font-medium mt-3">
          {text}
        </span>
      </div>
    </div>
  );
};

export default Loading;
