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

type AppPoweredByFooterProps = {
  className?: string;
};

/**
 * Global sticky bottom bar: “All Rights Reserved. Powered By {app name}”.
 * 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(
        "sticky bottom-0 z-40 shrink-0 border-t border-primary/20 bg-primary px-3 py-1 text-center text-[11px] leading-none text-primary-foreground sm:text-xs",
        className,
      )}
    >
      <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>
      )}
    </footer>
  );
}
