import { c as _c } from "react/compiler-runtime";
import * as React from 'react';
import { useMemo } from 'react';
import { useTerminalSize } from '../../../hooks/useTerminalSize.js';
import { Box, NoSelect, Text } from '../../../ink.js';
import { intersperse } from '../../../utils/array.js';
import { getPatchForDisplay } from '../../../utils/diff.js';
import { HighlightedCode } from '../../HighlightedCode.js';
import { StructuredDiff } from '../../StructuredDiff.js';
type Props = {
  file_path: string;
  content: string;
  fileExists: boolean;
  oldContent: string;
};
export function FileWriteToolDiff(t0) {
  const $ = _c(15);
  const {
    file_path,
    content,
    fileExists,
    oldContent
  } = t0;
  const {
    columns
  } = useTerminalSize();
  let t1;
  bb0: {
    if (!fileExists) {
      t1 = null;
      break bb0;
    }
    let t2;
    if ($[0] !== content || $[1] !== file_path || $[2] !== oldContent) {
      t2 = getPatchForDisplay({
        filePath: file_path,
        fileContents: oldContent,
        edits: [{
          old_string: oldContent,
          new_string: content,
          replace_all: false
        }]
      });
      $[0] = content;
      $[1] = file_path;
      $[2] = oldContent;
      $[3] = t2;
    } else {
      t2 = $[3];
    }
    t1 = t2;
  }
  const hunks = t1;
  let t2;
  if ($[4] !== content) {
    t2 = content.split("\n")[0] ?? null;
    $[4] = content;
    $[5] = t2;
  } else {
    t2 = $[5];
  }
  const firstLine = t2;
  let t3;
  if ($[6] !== columns || $[7] !== content || $[8] !== file_path || $[9] !== firstLine || $[10] !== hunks || $[11] !== oldContent) {
    t3 = hunks ? intersperse(hunks.map(_ => <StructuredDiff key={_.newStart} patch={_} dim={false} filePath={file_path} firstLine={firstLine} fileContent={oldContent} width={columns - 2} />), _temp) : <HighlightedCode code={content || "(No content)"} filePath={file_path} />;
    $[6] = columns;
    $[7] = content;
    $[8] = file_path;
    $[9] = firstLine;
    $[10] = hunks;
    $[11] = oldContent;
    $[12] = t3;
  } else {
    t3 = $[12];
  }
  let t4;
  if ($[13] !== t3) {
    t4 = <Box flexDirection="column"><Box borderColor="subtle" borderStyle="dashed" flexDirection="column" borderLeft={false} borderRight={false} paddingX={1}>{t3}</Box></Box>;
    $[13] = t3;
    $[14] = t4;
  } else {
    t4 = $[14];
  }
  return t4;
}
function _temp(i) {
  return <NoSelect fromLeftEdge={true} key={`ellipsis-${i}`}><Text dimColor={true}>...</Text></NoSelect>;
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJSZWFjdCIsInVzZU1lbW8iLCJ1c2VUZXJtaW5hbFNpemUiLCJCb3giLCJOb1NlbGVjdCIsIlRleHQiLCJpbnRlcnNwZXJzZSIsImdldFBhdGNoRm9yRGlzcGxheSIsIkhpZ2hsaWdodGVkQ29kZSIsIlN0cnVjdHVyZWREaWZmIiwiUHJvcHMiLCJmaWxlX3BhdGgiLCJjb250ZW50IiwiZmlsZUV4aXN0cyIsIm9sZENvbnRlbnQiLCJGaWxlV3JpdGVUb29sRGlmZiIsInQwIiwiJCIsIl9jIiwiY29sdW1ucyIsInQxIiwiYmIwIiwidDIiLCJmaWxlUGF0aCIsImZpbGVDb250ZW50cyIsImVkaXRzIiwib2xkX3N0cmluZyIsIm5ld19zdHJpbmciLCJyZXBsYWNlX2FsbCIsImh1bmtzIiwic3BsaXQiLCJmaXJzdExpbmUiLCJ0MyIsIm1hcCIsIl8iLCJuZXdTdGFydCIsIl90ZW1wIiwidDQiLCJwYWRkaW5nWCIsImkiXSwic291cmNlcyI6WyJGaWxlV3JpdGVUb29sRGlmZi50c3giXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0ICogYXMgUmVhY3QgZnJvbSAncmVhY3QnXG5pbXBvcnQgeyB1c2VNZW1vIH0gZnJvbSAncmVhY3QnXG5pbXBvcnQgeyB1c2VUZXJtaW5hbFNpemUgfSBmcm9tICcuLi8uLi8uLi9ob29rcy91c2VUZXJtaW5hbFNpemUuanMnXG5pbXBvcnQgeyBCb3gsIE5vU2VsZWN0LCBUZXh0IH0gZnJvbSAnLi4vLi4vLi4vaW5rLmpzJ1xuaW1wb3J0IHsgaW50ZXJz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wgW2ZpbGVFeGlzdHMsIGZpbGVfcGF0aCwgb2xkQ29udGVudCwgY29udGVudF0pXG5cbiAgY29uc3QgZmlyc3RMaW5lID0gY29udGVudC5zcGxpdCgnXFxuJylbMF0gPz8gbnVsbFxuICBjb25zdCBwYWRkaW5nWCA9IDFcblxuICByZXR1cm4gKFxuICAgIDxCb3ggZmxleERpcmVjdGlvbj1cImNvbHVtblwiPlxuICAgICAgPEJveFxuICAgICAgICBib3JkZXJDb2xvcj1cInN1YnRsZVwiXG4gICAgICAgIGJvcmRlclN0eWxlPVwiZGFzaGVkXCJcbiAgICAgICAgZmxleERpcmVjdGlvbj1cImNvbHVtblwiXG4gICAgICAgIGJvcmRlckxlZnQ9e2ZhbHNlfVxuICAgICAgICBib3JkZXJSaWdodD17ZmFsc2V9XG4gICAgICAgIHBhZGRpbmdYPXtwYWRkaW5nWH1cbiAgICAgID5cbiAgICAgICAge2h1bmtzID8gKFxuICAgICAgICAgIGludGVyc3BlcnNlKFxuICAgICAgICAgICAgaHVua3MubWFwKF8gPT4gKFxuICAgICAgICAgICAgICA8U3RydWN0dXJlZERpZmZcbiAgICAgICAgICAgICAgICBrZXk9e18ubmV3U3RhcnR9XG4gICAgICAgICAgICAgICAgcGF0Y2g9e199XG4gICAgICAgICAgICAgICAgZGltPXtmYWxzZX1cbiAgICAgICAgICAgICAgICBmaWxlUGF0aD17ZmlsZV9wYXRofVxuICAgICAgICAgICAgICAgIGZpcnN0TGluZT17Zmlyc3RMaW5lfVxuICAgICAgICAgICAgICAgIGZpbGVDb250ZW50PXtvbGRDb250ZW50fVxuICAgICAgICAgICAgICAgIHdpZHRoPXtjb2x1bW5zIC0gMiAqIHBhZGRpbmdYfVxuICAgICAgICAgICAgICAvPlxuICAgICAgICAgICAgKSksXG4gICAgICAgICAgICBpID0+IChcbiAgICAgICAgICAgICAgPE5vU2VsZWN0IGZyb21MZWZ0RWRnZSBrZXk9e2BlbGxpcHNpcy0ke2l9YH0+XG4gICAgICAgICAgICA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