"use client";
import { useMemo } from "react";
import { IconGitBranch } from "@tabler/icons-react";
import { cn } from "@/lib/utils";
import type { Branch } from "@/lib/types/http";
import { scoreBranch } from "@/lib/utils/branch-filter";
import {
Pill,
sortBranches,
branchToOption,
computeBranchPlaceholder,
} from "@/components/task-create-dialog-pill";
function computeUrlBranchDisabledReason({
hasUrl,
branchesLoading,
optionCount,
}: {
hasUrl: boolean;
branchesLoading: boolean;
optionCount: number;
}): string | undefined {
if (!hasUrl) return "Enter a GitHub URL first.";
if (branchesLoading) return "Loading branches…";
if (optionCount === 0) return "No branches available for this URL.";
return undefined;
}
export function GitHubUrlSection({
githubUrl,
githubUrlError,
githubBranch,
githubBranches,
githubBranchesLoading,
onGitHubUrlChange,
onGitHubBranchChange,
}: {
githubUrl: string;
githubUrlError: string | null;
githubBranch: string;
githubBranches: Branch[];
githubBranchesLoading: boolean;
onGitHubUrlChange?: (value: string) => void;
onGitHubBranchChange: (value: string) => void;
}) {
// URL mode is always remote-clone-based, so the branch is freely
// selectable regardless of executor type. Local executor's "branch is
// dictated by the user's checkout" rule does not apply here — there is
// no pre-existing local checkout for an arbitrary GitHub URL.
const branchOptions = useMemo(
() => sortBranches(githubBranches).map(branchToOption),
[githubBranches],
);
const branchPlaceholder = computeBranchPlaceholder(
!!githubUrl.trim(),
githubBranchesLoading,
branchOptions.length,
);
return (
<>