import { useState } from "react";
import { mergePull, recheckMergeability, updatePull } from "~/fns/pulls";
import { useAction } from "~/hooks/use-action";
import { StatusList } from "./StatusList";
import { MergeAutomation } from "./MergeAutomation";
import { Badge, Panel, StatusDot } from "./ui/Primitives";
import { Button } from "./ui/Button";
import { CheckboxField, ErrorBanner, SelectField, TextAreaField } from "./ui/Field";
import type { usePull } from "~/hooks/use-pull";
type PullData = ReturnType<typeof usePull>;
const METHODS = [
{ value: "merge", label: "Create a merge commit" },
{ value: "squash", label: "Squash and merge" },
{ value: "rebase", label: "Rebase and merge" },
] as const;
/** The browser's UTC offset as git's `+HHMM`, so rebased commits carry the merger's local timezone. */
function browserTimezone(): string {
const offset = -new Date().getTimezoneOffset();
const absolute = Math.abs(offset);
const hours = String(Math.floor(absolute / 60)).padStart(2, "0");
const minutes = String(absolute % 60).padStart(2, "0");
return `${offset < 0 ? "-" : "+"}${hours}${minutes}`;
}
export function MergeBox({ owner, repo, data }: { owner: string; repo: string; data: PullData }) {
const { pull, gate, checks, checksState } = data;
const [method, setMethod] = useState<(typeof METHODS)[number]["value"]>("merge");
const merge = useAction(mergePull);
const recheck = useAction(recheckMergeability);
const ready = useAction(updatePull);
const number = pull.number;
if (pull.merged) {
return (
<Panel>
<div className="flex items-center gap-3 p-4 text-sm">
<Badge tone="purple">Merged</Badge>