import type { HttpRequestHeader } from "@yaakapp-internal/models"; import { HStack, CountBadge } from "@yaakapp-internal/ui"; import { acceptLanguages } from "../lib/data/acceptLanguages"; import { cacheControlDirectives } from "../lib/data/cacheControl"; import { charsets } from "../lib/data/charsets"; import { connections } from "../lib/data/connections"; import { encodings } from "../lib/data/encodings"; import type { HeaderValuePreset } from "../lib/data/headerValuePresets"; import { headerNames } from "../lib/data/headerNames"; import { mimeTypes } from "../lib/data/mimetypes"; import { userAgents } from "../lib/data/userAgents"; import { validateHttpHeader } from "../lib/validateHttpHeader"; import { DetailsBanner } from "./core/DetailsBanner"; import type { GenericCompletion, GenericCompletionConfig } from "./core/Editor/genericCompletion"; import type { InputProps } from "./core/Input"; import type { Pair, PairEditorProps } from "./core/PairEditor"; import { PairEditorRow } from "./core/PairEditor"; import { ensurePairId } from "./core/PairEditor.util"; import { PairOrBulkEditor } from "./core/PairOrBulkEditor"; type Props = { forceUpdateKey: string; headers: HttpRequestHeader[]; inheritedHeaders?: HttpRequestHeader[]; inheritedHeadersLabel?: string; stateKey: string; onChange: (headers: HttpRequestHeader[]) => void; label?: string; }; export function HeadersEditor({ stateKey, headers, inheritedHeaders, inheritedHeadersLabel = "Inherited", onChange, forceUpdateKey, }: Props) { // Get header names defined at current level (case-insensitive) const currentHeaderNames = new Set( headers.filter((h) => h.name).map((h) => h.name.toLowerCase()), ); // Filter inherited headers: must be enabled, have content, and not be overridden by current level const validInheritedHeaders = inheritedHeaders?.filter( (pair) => pair.enabled && (pair.name || pair.value) && !currentHeaderNames.has(pair.name.toLowerCase()), ) ?? []; const hasInheritedHeaders = validInheritedHeaders.length > 0; return (