<commit_before>import React from 'react'
import { translate } from 'cozy-ui/react/I18n'
import styles from '../styles/konnectorEdit'

import { Tab, Tabs, TabList, TabPanels, TabPanel } from 'cozy-ui/react/Tabs'

import AccountConnectionData from './AccountConnectionData'
import AccountLoginForm from './AccountLoginForm'
import AccountLogout from './AccountLogout'
import DescriptionContent from './DescriptionContent'
import KonnectorFolder from './KonnectorFolder'
import KonnectorSync from './KonnectorSync'

import { ACCOUNT_ERRORS } from '../lib/accounts'

const NotExistingDirErrorDescription = ({ t, connector }) => (<DescriptionContent
  cssClassesObject={{'coz-error': true}}
  title={t('connection.error.NOT_EXISTING_DIRECTORY.title')}
  messages={[t('connection.error.NOT_EXISTING_DIRECTORY.description', {name: connector.name})]}
/>)

const GlobalErrorDescription = ({ t, connector }) => (<DescriptionContent
  cssClassesObject={{'coz-error': true}}
  title={t('connection.error.default.title')}
  messages={[t('connection.error.default.description', {name: connector.name})]}
/>)

const getErrorDescription = (props) => {
  const { error } = props
  switch (error.message) {
    case ACCOUNT_ERRORS.NOT_EXISTING_DIRECTORY:
      return (<NotExistingDirErrorDescription {...props} />)
    default:
      return (<GlobalErrorDescription {...props} />)
  }
}

export const KonnectorEdit = ({ t, account, connector, deleting, disableSuccessTimeout, driveUrl, error, fields, folderPath, isUnloading, lastSync, oAuthTerminated, onCancel, onDelete, onForceConnection, onSubmit, submitting, success }) => {
  const warningIcon = <svg className='item-status-icon'>
    <use xlinkHref={require('../assets/sprites/icon-warning.svg')} /> }
  </svg>
  const hasLoginError = error && error.message === ACCOUNT_ERRORS.LOGIN_FAILED
  const hasErrorExceptLogin = error && error.message !== ACCOUNT_ERRORS.LOGIN_FAILED
  const { hasDescriptions } = connector

  return (
    <div className={styles['col-account-edit-content']}>

      { hasErrorExceptLogin && getErrorDescription({t, error, connector})}

      <Tabs
        initialActiveTab={
          hasLoginError
          ? 'account'
          : 'sync'
        }
        className={styles['col-account-edit-tabs']}
      >

        <TabList>
          <Tab name='sync' className={styles['col-account-edit-tab']}>
            {t('account.config.tabs.sync')}
            { hasErrorExceptLogin && warningIcon}
          </Tab>
          <Tab name='account' className={styles['col-account-edit-tab']}>
            {t('account.config.tabs.account')}
            { hasLoginError && warningIcon }
          </Tab>
          <Tab name='data' className={styles['col-account-edit-tab']}>
            {t('account.config.tabs.data')}
          </Tab>
        </TabList>

        <TabPanels>

          <TabPanel name='sync' className={styles['col-account-edit-tabpanel']}>
            { !success && <KonnectorSync
              frequency={account && account.auth && account.auth.frequency}
              date={lastSync}
              submitting={submitting}
              onForceConnection={onForceConnection}
            /> }
            { !success && folderPath && <KonnectorFolder
              connector={connector}
              account={account}
              driveUrl={driveUrl}
            /> }
          </TabPanel>

          <TabPanel name='account' className={styles['col-account-edit-tabpanel']}><commit_msg>fix: bug about empty sync tab when account update :bug:<commit_after>import React from 'react'
import { translate } from 'cozy-ui/react/I18n'
import styles from '../styles/konnectorEdit'

import { Tab, Tabs, TabList, TabPanels, TabPanel } from 'cozy-ui/react/Tabs'

import AccountConnectionData from './AccountConnectionData'
import AccountLoginForm from './AccountLoginForm'
import AccountLogout from './AccountLogout'
import DescriptionContent from './DescriptionContent'
import KonnectorFolder from './KonnectorFolder'
import KonnectorSync from './KonnectorSync'

import { ACCOUNT_ERRORS } from '../lib/accounts'

const NotExistingDirErrorDescription = ({ t, connector }) => (<DescriptionContent
  cssClassesObject={{'coz-error': true}}
  title={t('connection.error.NOT_EXISTING_DIRECTORY.title')}
  messages={[t('connection.error.NOT_EXISTING_DIRECTORY.description', {name: connector.name})]}
/>)

const GlobalErrorDescription = ({ t, connector }) => (<DescriptionContent
  cssClassesObject={{'coz-error': true}}
  title={t('connection.error.default.title')}
  messages={[t('connection.error.default.description', {name: connector.name})]}
/>)

const getErrorDescription = (props) => {
  const { error } = props
  switch (error.message) {
    case ACCOUNT_ERRORS.NOT_EXISTING_DIRECTORY:
      return (<NotExistingDirErrorDescription {...props} />)
    default:
      return (<GlobalErrorDescription {...props} />)
  }
}

export const KonnectorEdit = ({ t, account, connector, deleting, disableSuccessTimeout, driveUrl, error, fields, folderPath, isUnloading, lastSync, oAuthTerminated, onCancel, onDelete, onForceConnection, onSubmit, submitting, success }) => {
  const warningIcon = <svg className='item-status-icon'>
    <use xlinkHref={require('../assets/sprites/icon-warning.svg')} /> }
  </svg>
  const hasLoginError = error && error.message === ACCOUNT_ERRORS.LOGIN_FAILED
  const hasErrorExceptLogin = error && error.message !== ACCOUNT_ERRORS.LOGIN_FAILED
  const { hasDescriptions } = connector

  return (
    <div className={styles['col-account-edit-content']}>

      { hasErrorExceptLogin && getErrorDescription({t, error, connector})}

      <Tabs
        initialActiveTab={
          hasLoginError
          ? 'account'
          : 'sync'
        }
        className={styles['col-account-edit-tabs']}
      >

        <TabList>
          <Tab name='sync' className={styles['col-account-edit-tab']}>
            {t('account.config.tabs.sync')}
            { hasErrorExceptLogin && warningIcon}
          </Tab>
          <Tab name='account' className={styles['col-account-edit-tab']}>
            {t('account.config.tabs.account')}
            { hasLoginError && warningIcon }
          </Tab>
          <Tab name='data' className={styles['col-account-edit-tab']}>
            {t('account.config.tabs.data')}
          </Tab>
        </TabList>

        <TabPanels>

          <TabPanel name='sync' className={styles['col-account-edit-tabpanel']}>
            { lastSync && account.auth && account.auth.frequency && <KonnectorSync
              frequency={account && account.auth && account.auth.frequency}
              date={lastSync}
              submitting={submitting}
              onForceConnection={onForceConnection}
            /> }
            { folderPath && <KonnectorFolder
              connector={connector}
              account={account}
              driveUrl={driveUrl}
            /> }
          </TabPanel>

          <TabPanel name='account' className={styles['col-account-edit-tabpanel']}>
{'fraction_non_alphanumeric': 0.14069202173291392, 'fraction_numerical': 0.0005719187875321705, 'mean_word_length': 3.2113184828416617, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 57, 'https://': 0, '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': '4647436', 'n_tokens_mistral': 2004, 'n_tokens_neox': 1959, 'n_words': 377}