<commit_before>import React from 'react'
import { parseRepositoryIdentifier } from '../../lib/remote-parsing'
import { ISubmoduleDiff } from '../../models/diff'
import { LinkButton } from '../lib/link-button'
import { Octicon } from '../octicons'
import * as OcticonSymbol from '../octicons/octicons.generated'
import { SuggestedAction } from '../suggested-actions'

interface ISubmoduleDiffProps {
  readonly onOpenSubmodule?: (fullPath: string) => void
  readonly diff: ISubmoduleDiff
}

export class SubmoduleDiff extends React.Component<ISubmoduleDiffProps> {
  public constructor(props: ISubmoduleDiffProps) {
    super(props)
  }

  public render() {
    return (
      <div id="submodule-diff">
        <div className="content">
          <div className="header">
            <div className="text">
              <h1>Submodule changes</h1>
            </div>
          </div>
          {this.renderSubmoduleInfo()}
          {this.renderCommitChangeInfo()}
          {this.renderSubmodulesChangesInfo()}
          {this.renderOpenSubmoduleAction()}
        </div>
      </div>
    )
  }

  private renderSubmoduleInfo() {
    // TODO: only for GH submodules?

    const repoIdentifier = parseRepositoryIdentifier(this.props.diff.url)
    if (repoIdentifier === null) {
      return null
    }

    const hostname =
      repoIdentifier.hostname === 'github.com'
        ? ''
        : ` (${repoIdentifier.hostname})`

    return (
      <p>
        <Octicon symbol={OcticonSymbol.info} /> This is a submodule based on the
        repository{' '}
        <LinkButton
          uri={`https://${repoIdentifier.hostname}/${repoIdentifier.owner}/${repoIdentifier.name}`}
        >
          {repoIdentifier.owner}/{repoIdentifier.name}
          {hostname}
        </LinkButton>
        .
      </p>
    )
  }

  private renderCommitChangeInfo() {
    const { diff } = this.props

    if (!diff.status.commitChanged) {
      return null
    }

    return (
      <p>
        <Octicon symbol={OcticonSymbol.diffModified} /> This submodule has
        changed its commit from <LinkButton>{diff.oldSHA}</LinkButton> to{' '}
        <LinkButton>{diff.newSHA}</LinkButton>. This change can be committed to
        the parent repository.
      </p>
    )
  }

  private renderSubmodulesChangesInfo() {
    return (
      <p>
        <Octicon symbol={OcticonSymbol.fileDiff} /> This submodule has modified<commit_msg>WIP Remove parts of the interstitial when not needed<commit_after>import React from 'react'
import { parseRepositoryIdentifier } from '../../lib/remote-parsing'
import { ISubmoduleDiff } from '../../models/diff'
import { LinkButton } from '../lib/link-button'
import { Octicon } from '../octicons'
import * as OcticonSymbol from '../octicons/octicons.generated'
import { SuggestedAction } from '../suggested-actions'

interface ISubmoduleDiffProps {
  readonly onOpenSubmodule?: (fullPath: string) => void
  readonly diff: ISubmoduleDiff
}

export class SubmoduleDiff extends React.Component<ISubmoduleDiffProps> {
  public constructor(props: ISubmoduleDiffProps) {
    super(props)
  }

  public render() {
    return (
      <div id="submodule-diff">
        <div className="content">
          <div className="header">
            <div className="text">
              <h1>Submodule changes</h1>
            </div>
          </div>
          {this.renderSubmoduleInfo()}
          {this.renderCommitChangeInfo()}
          {this.renderSubmodulesChangesInfo()}
          {this.renderOpenSubmoduleAction()}
        </div>
      </div>
    )
  }

  private renderSubmoduleInfo() {
    // TODO: only for GH submodules?
    // TODO: test with submodules without URL (is that possible? maybe a submodule
    // from a local repo??)

    const repoIdentifier = parseRepositoryIdentifier(this.props.diff.url)
    if (repoIdentifier === null) {
      return null
    }

    const hostname =
      repoIdentifier.hostname === 'github.com'
        ? ''
        : ` (${repoIdentifier.hostname})`

    return (
      <p>
        <Octicon symbol={OcticonSymbol.info} /> This is a submodule based on the
        repository{' '}
        <LinkButton
          uri={`https://${repoIdentifier.hostname}/${repoIdentifier.owner}/${repoIdentifier.name}`}
        >
          {repoIdentifier.owner}/{repoIdentifier.name}
          {hostname}
        </LinkButton>
        .
      </p>
    )
  }

  private renderCommitChangeInfo() {
    const { diff } = this.props

    if (!diff.status.commitChanged) {
      return null
    }

    return (
      <p>
        <Octicon symbol={OcticonSymbol.diffModified} /> This submodule has
        changed its commit from <LinkButton>{diff.oldSHA}</LinkButton> to{' '}
        <LinkButton>{diff.newSHA}</LinkButton>. This change can be committed to
        the parent repository.
      </p>
    )
  }

  private renderSubmodulesChangesInfo() {
    const { diff } = this.props

    if (!diff.status.untrackedChanges) {
      return null
    }

    return (
      <p>
        <Octicon symbol={OcticonSymbol.fileDiff} /> This submodule has modified
{'fraction_non_alphanumeric': 0.12438399369209541, 'fraction_numerical': 0.000788488074117879, 'mean_word_length': 2.4993103448275864, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 55, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5917177', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1437, 'n_words': 330}