import { getCurrentWindow } from "@tauri-apps/api/window";
import { buttonClass } from "../ui/primitives";

async function minimizeWindow() {
  try {
    await getCurrentWindow().minimize();
  } catch (error) {
    console.error("Unable to minimize window:", error);
  }
}

async function toggleMaximizeWindow() {
  try {
    await getCurrentWindow().toggleMaximize();
  } catch (error) {
    console.error("Unable to toggle maximize:", error);
  }
}

async function closeWindow() {
  try {
    await getCurrentWindow().close();
  } catch (error) {
    console.error("Unable to close window:", error);
  }
}

export default function WindowControls() {
  return (
    <div className="flex items-center gap-1">
      <button
        type="button"
        onClick={() => void minimizeWindow()}
        title="Minimize"
        className={`${buttonClass({ variant: "secondary", size: "icon" })} border border-gray-300`}
      >
        _
      </button>
      <button
        type="button"
        onClick={() => void toggleMaximizeWindow()}
        title="Maximize / Restore"
        className={`${buttonClass({ variant: "secondary", size: "icon" })} border border-gray-300`}
      >
        []
      </button>
      <button
        type="button"
        onClick={() => void closeWindow()}
        title="Close"
        className={`${buttonClass({ variant: "dangerSoft", size: "icon" })} border border-red-300`}
      >
        X
      </button>
    </div>
  );
}
