import {
ContextMenu,
Dropdown,
type DropdownItem,
Icon,
IconButton,
ResizeHandle,
} from "@yaakapp-internal/ui";
import classNames from "classnames";
import { useSetAtom } from "jotai";
import { memo, type MouseEvent, useCallback, useRef, useState } from "react";
import {
type Column,
COLUMNS,
type ColumnId,
type ColumnPrefs,
type FlowSort,
resetWidths,
resizeColumn,
toggleColumn,
} from "../lib/columns";
import { useExportShownHar } from "../lib/flowActions";
import { columnPrefsAtom } from "../lib/store";
interface Props {
columns: Column[];
template: string;
prefs: ColumnPrefs;
sort: FlowSort | null;
onSort: (column: ColumnId) => void;
onSortByStart: () => void;
}
/**
* The list's only control surface: a click on a label sorts by it and a second reverses it,
* dragging the edge after a label resizes its column, and the picker sits in the empty corner on
* hover, or anywhere on a right-click.
*/
export const FlowListHeader = memo(function FlowListHeader({
columns,
template,
prefs,
sort,
onSort,
onSortByStart,
}: Props) {
const setPrefs = useSetAtom(columnPrefsAtom);
const exportShown = useExportShownHar();
const [menu, setMenu] = useState<{ x: number; y: number } | null>(null);
// Widths when a drag began, so each move sets the width from where it started.
const startWidth = useRef(0);
const items: DropdownItem[] = [
{
type: "content",
label: