// Libs
// -----------------------------------------------------------------------------
import React, { FC, Fragment } from 'react';
import { Form, Input, Row, Col } from 'antd';
import { Rule } from 'antd/lib/form';

// App
// -----------------------------------------------------------------------------
import { CommonActionFormProps } from './CommonActionFormProps';
import { useCorrelationRulesTemplateMessages } from '../../i18n';

export const ExecActionForm: FC<CommonActionFormProps> = ({
  name,
  isDisabled,
}) => {
  const locale = useCorrelationRulesTemplateMessages();
  const fieldStrings =
    locale.actionsRuleMessage.blockMessages.runExecutableFileMessage;
  const fieldRules: Array<Rule> = [
    { required: true, message: locale.formValidationMessages.emptyField },
  ];

  return (
    <Fragment>
      <Form.Item name={[name, 'type']} rules={fieldRules} hidden>
        <Input type="hidden" disabled={isDisabled} />
      </Form.Item>

      <Row gutter={[32, 0]}>
        <Col span={24}>
          <Form.Item
            name={[name, 'path']}
            label={fieldStrings.executablePath.title}
            rules={fieldRules}
          >
            <Input
              placeholder={fieldStrings.executablePath.placeholder}
              disabled={isDisabled}
            />
          </Form.Item>
        </Col>
      </Row>

      <Row gutter={[32, 0]}>
        <Col span={24}>
          <Form.Item name={[name, 'args']} label={fieldStrings.arguments.title}>
            <Input
              placeholder={fieldStrings.arguments.placeholder}
              disabled={isDisabled}
            />
          </Form.Item>
        </Col>
      </Row>

      <Row gutter={[32, 0]}>
        <Col span={24}>
          <Form.Item
            name={[name, 'env']}
            label={fieldStrings.environment.title}
          >
            <Input
              placeholder={fieldStrings.environment.placeholder}
              disabled={isDisabled}
            />
          </Form.Item>
        </Col>
      </Row>

      <Row gutter={[32, 0]}>
        <Col span={24}>
          <Form.Item
            name={[name, 'cwd']}
            label={fieldStrings.workingDirectory.title}
          >
            <Input
              placeholder={fieldStrings.workingDirectory.placeholder}
              disabled={isDisabled}
            />
          </Form.Item>
        </Col>
      </Row>
    </Fragment>
  );
};
