import { getCurrentWindow } from "@tauri-apps/api/window";

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="h-7 w-7 rounded border border-gray-300 bg-white text-xs text-gray-700 hover:bg-gray-100"
      >
        _
      </button>
      <button
        type="button"
        onClick={() => void toggleMaximizeWindow()}
        title="Maximize / Restore"
        className="h-7 w-7 rounded border border-gray-300 bg-white text-xs text-gray-700 hover:bg-gray-100"
      >
        []
      </button>
      <button
        type="button"
        onClick={() => void closeWindow()}
        title="Close"
        className="h-7 w-7 rounded border border-red-300 bg-red-50 text-xs text-red-700 hover:bg-red-100"
      >
        X
      </button>
    </div>
  );
}
