import * as React from 'react'
import { Dialog, DialogContent, DialogFooter } from '../dialog'
import { OkCancelButtonGroup } from '../dialog/ok-cancel-button-group'
import { setGlobalConfigValue } from '../../lib/git'

interface ISChannelNoRevocationCheckDialogProps {
  readonly url: string

  readonly onDismissed: () => void
}
interface ISChannelNoRevocationCheckDialogState {
  readonly loading: boolean
}

export class SChannelNoRevocationCheckDialog extends React.Component<
  ISChannelNoRevocationCheckDialogProps,
  ISChannelNoRevocationCheckDialogState
> {
  public constructor(props: ISChannelNoRevocationCheckDialogProps) {
    super(props)
    this.state = { loading: false }
  }

  private onDisableRevocationChecks = async () => {
    this.setState({ loading: true })
    await setGlobalConfigValue('http.schannelCheckRevoke', 'false')
    this.props.onDismissed()
  }

  public render() {
    return (
      <Dialog
        title="Certificate revocation check failed"
        loading={this.state.loading}
        onDismissed={this.props.onDismissed}
        onSubmit={this.onDisableRevocationChecks}
        type="error"
      >
        <DialogContent>
          <p>
            Error when attempting to access '{this.props.url}', unable to
            perform certificate revocation check. See the Event Viewer for more
            details.
          </p>
          <p>
            A common cause for this error is This error is common when accessing
            the Internet through a corporate proxy server or a debugging proxy
            that performs SSL inspection.
          </p>
          <p>
            Would you like to turn off certificate revocation checks? You can
            change this at any time in options.
          </p>
        </DialogContent>
        <DialogFooter>
          <OkCancelButtonGroup okButtonText="Disable revocation checks" />
        </DialogFooter>
      </Dialog>
    )
  }
}

Add an initial dialog for the schannel error
Add an initial dialog for the schannel error
