// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../../ui/kit/kit.js';
import * as Common from '../../core/common/common.js';
import * as i18n from '../../core/i18n/i18n.js';
import * as Persistence from '../../models/persistence/persistence.js';
import type * as Workspace from '../../models/workspace/workspace.js';
import * as WorkspaceDiff from '../../models/workspace_diff/workspace_diff.js';
import type * as Diff from '../../third_party/diff/diff.js';
import * as Buttons from '../../ui/components/buttons/buttons.js';
import type * as DiffView from '../../ui/components/diff_view/diff_view.js';
import * as UI from '../../ui/legacy/legacy.js';
import * as Lit from '../../ui/lit/lit.js';
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
import * as PanelUtils from '../utils/utils.js';
import combinedDiffViewStyles from './combinedDiffView.css.js';
const COPIED_TO_CLIPBOARD_TEXT_TIMEOUT_MS = 1000;
const {html, Directives: {classMap}} = Lit;
const UIStrings = {
/**
* @description The title of the button after it was pressed and the text was copied to clipboard.
*/
copied: 'Copied to clipboard',
/**
* @description The title of the copy file to clipboard button
* @example {index.css} PH1
*/
copyFile: 'Copy file {PH1} to clipboard',
} as const;
const str_ = i18n.i18n.registerUIStrings('panels/changes/CombinedDiffView.ts', UIStrings);
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
interface SingleDiffViewInput {
// `DiffArray` can be empty for the modified files that
// do not have any diff. (e.g. the file content transition was A -> B -> A)
diff: Diff.Diff.DiffArray;
fileName: string;
fileUrl: string;
mimeType: string;
icon: Lit.TemplateResult;
copied: boolean;
selectedFileUrl?: string;
onCopy: (fileUrl: string) => void;
onFileNameClick: (fileUrl: string) => void;
}
export interface ViewOutput {
scrollToSelectedDiff?: () => void;
}
export interface ViewInput {
singleDiffViewInputs: SingleDiffViewInput[];
}
type View = (input: ViewInput, output: ViewOutput, target: HTMLElement) => void;
function renderSingleDiffView(singleDiffViewInput: SingleDiffViewInput): Lit.TemplateResult {
const {fileName, fileUrl, mimeType, icon, diff, copied, selectedFileUrl, onCopy, onFileNameClick} =
singleDiffViewInput;
const classes = classMap({
selected: selectedFileUrl === fileUrl,
});
// clang-format off
return html`