"use client";
import React from "react";

interface LangSwitchProps {
  basePath?: string;
  locale?: string;
}

export function LangSwitch({ basePath = "", locale = "zh-CN" }: LangSwitchProps) {
  const onSwitch = () => {
    const current = window.location.pathname;
    const parts = current.split("/").filter(Boolean);
    const currentLocale = parts[0] === "en" ? "en" : parts[0] === "zh-CN" ? "zh-CN" : null;
    const nextLocale = currentLocale === "en" ? "zh-CN" : "en";
    if (currentLocale) {
      parts[0] = nextLocale;
    } else {
      parts.unshift(nextLocale);
    }
    const nextPath = "/" + parts.join("/");
    window.location.assign(nextPath);
  };
  const buttonText = locale === "en" ? "CN" : "EN";
  return (
    <button
      onClick={onSwitch}
      className="bg-transparent border border-[rgba(255,255,255,0.06)] text-huilong-muted px-2 py-1.5 rounded text-xs md:text-sm cursor-pointer hover:text-white hover:border-[rgba(255,255,255,0.1)] active:opacity-80 transition-colors touch-manipulation"
    >
      {buttonText}
    </button>
  );
}


