import { APP_CONFIG } from "@/config/app-config";
import { cn } from "@/lib/utils";

type AppPoweredByFooterProps = {
  className?: string;
};

/**
 * Global bottom strip: “All Rights Reserved. Powered By {app name}” as a centred bubble.
 * The strip is fixed to the viewport and `--app-footer-height` tall; the app shell and the
 * sidebar are sized to `--app-shell-height` (see globals.css), so every sidebar style ends
 * above it and nothing scrolls underneath.
 * The name links out only when NEXT_PUBLIC_APP_POWERED_BY_URL names a site for this brand;
 * otherwise it renders as plain text rather than pointing at some other deployment.
 */
export function AppPoweredByFooter({ className }: AppPoweredByFooterProps) {
  return (
    <footer
      className={cn(
        "pointer-events-none fixed inset-x-0 bottom-0 z-40 flex h-(--app-footer-height) items-center justify-center px-3 text-center text-[11px] leading-none text-primary-foreground sm:text-xs",
        className,
      )}
    >
      <div className="pointer-events-auto whitespace-nowrap rounded-full border border-primary/20 bg-primary px-3 py-1 shadow-sm">
        <span>All Rights Reserved. Powered By </span>
        {APP_CONFIG.poweredByUrl ? (
          <a
            href={APP_CONFIG.poweredByUrl}
            target="_blank"
            rel="noopener noreferrer"
            className="font-medium underline underline-offset-2 hover:text-primary-foreground/90"
          >
            {APP_CONFIG.name}
          </a>
        ) : (
          <span className="font-medium">{APP_CONFIG.name}</span>
        )}
      </div>
    </footer>
  );
}
