content: import PropTypes from 'prop-types';
  import React from 'react';
  import Alert from 'Components/Alert';
  import Form from 'Components/Form/Form';
  import FormGroup from 'Components/Form/FormGroup';
  import FormInputGroup from 'Components/Form/FormInputGroup';
  import FormLabel from 'Components/Form/FormLabel';
  import ProviderFieldFormGroup from 'Components/Form/ProviderFieldFormGroup';
  import Button from 'Components/Link/Button';
  import SpinnerErrorButton from 'Components/Link/SpinnerErrorButton';
  import LoadingIndicator from 'Components/Loading/LoadingIndicator';
  import ModalBody from 'Components/Modal/ModalBody';
  import ModalContent from 'Components/Modal/ModalContent';
  import ModalFooter from 'Components/Modal/ModalFooter';
  import ModalHeader from 'Components/Modal/ModalHeader';
  import { inputTypes, kinds } from 'Helpers/Props';
  import NotificationEventItems from './NotificationEventItems';
  import styles from './EditNotificationModalContent.css';
  
  function EditNotificationModalContent(props) {
    const {
      advancedSettings,
      isFetching,
      error,
      isSaving,
      isTesting,
      saveError,
      item,
      onInputChange,
      onFieldChange,
      onModalClose,
      onSavePress,
      onTestPress,
      onDeleteNotificationPress,
      ...otherProps
    } = props;
  
    const {
      id,
      implementationName,
      name,
      tags,
      fields,
      message
    } = item;
  
    return (
      <ModalContent onModalClose={onModalClose}>
        <ModalHeader>
          {`${id ? 'Edit' : 'Add'} Connection - ${implementationName}`}
        </ModalHeader>
  
        <ModalBody>
          {
            isFetching &&
              <LoadingIndicator />
          }
  
          {
            !isFetching && !!error &&
              <div>Unable to add a new notification, please try again.</div>
          }
  
          {
            !isFetching && !error &&
              <Form {...otherProps}>
                {
                  !!message &&
                    <Alert
                      className={styles.message}
                      kind={message.value.type}
                    >
                      {message.value.message}
                    </Alert>
                }
  
                <FormGroup>
                  <FormLabel>Name</FormLabel>
  
                  <FormInputGroup
                    type={inputTypes.TEXT}
                    name="name"
                    {...name}
                    onChange={onInputChange}
                  />
                </FormGroup>
  
                <NotificationEventItems
                  item={item}
                  onInputChange={onInputChange}
                />
  
                <FormGroup>
                  <FormLabel>Tags</FormLabel>
  
                  <FormInputGroup
                    type={inputTypes.TAG}
                    name="tags"
                    helpText="Only send notifications for artist with at least one matching tag"
                    {...tags}
                    onChange={onInputChange}
                  />
                </FormGroup>
  
                {
                  fields.map((field) => {
                    return (
                      <ProviderFieldFormGroup
                        key={field.name}
                        advancedSettings={advancedSettings}
                        provider="notification"
                        providerData={item}
                        section="settings.notifications"
                        {...field}
                        onChange={onFieldChange}
                      />
                    );
                  })
                }
  
              </Form>
          }
        </ModalBody>
        <ModalFooter>
          {
            id &&
              <Button
                className={styles.deleteButton}
                kind={kinds.DANGER}
                onPress={onDeleteNotificationPress}
              >
                Delete
              </Button>
          }
  
          <SpinnerErrorButton
            isSpinning={isTesting}
            error={saveError}
            onPress={onTestPress}
          >
            Test
          </SpinnerErrorButton>
  
          <Button
            onPress={onModalClose}
          >
            Cancel
          </Button>
  
          <SpinnerErrorButton
            isSpinning={isSaving}
            error={saveError}
            onPress={onSavePress}
          >
            Save
          </SpinnerErrorButton>
        </ModalFooter>
      </ModalContent>
    );
  }
  
  EditNotificationModalContent.propTypes = {
    advancedSettings: PropTypes.bool.isRequired,
    isFetching: PropTypes.bool.isRequired,
    error: PropTypes.object,
    isSaving: PropTypes.bool.isRequired,
    isTesting: PropTypes.bool.isRequired,
    saveError: PropTypes.object,
    item: PropTypes.object.isRequired,
    onInputChange: PropTypes.func.isRequired,
    onFieldChange: PropTypes.func.isRequired,
    onModalClose: PropTypes.func.isRequired,
    onSavePress: PropTypes.func.isRequired,
    onTestPress: PropTypes.func.isRequired,
    onDeleteNotificationPress: PropTypes.func
  };
  
  export default EditNotificationModalContent;
  