import React from 'react';
import { Form, Button } from 'react-bootstrap';
import TextBox from '../../elements/textField';
import CheckBox from '../../elements/checkbox';
import Select from '../../elements/selectpicker';
import DateTime from '../../elements/datepicker';

class UtilsService {
  async isFormValid(formState) {// const { form } = formState.template;
    //     form.map(formList => {
    //         formList.formGroup.input(elem => {
    //             console.log("Error ==========>"+JSON.stringify(elem));
    //         })
    //     })
    // console.log("formData"+ JSON.stringify(formState));
    // return true;
  }

  async constructFormControlGroup(source) {
    //let formData;
    console.log('utils', source);
    source.forEach(element => {
      if (element.type === 'text') {}

      console.log('element', element.type);
    });
  }
  /*
  * template : form elements
  * formContent : array variable to push the form elements
  */


  async constructFormElements(template, formContent, scope) {
    if (template.type === "text" || template.type === "password" || template.type === "email") {
      formContent.push( /*#__PURE__*/React.createElement("div", {
        className: "col " + template.class,
        key: template.id + '00t'
      }, /*#__PURE__*/React.createElement(TextBox, {
        key: template.id,
        id: template.id,
        type: template.type,
        placeholder: template.placeholder,
        name: template.name,
        value: scope.state[template.name],
        label: template.labelName,
        onChange: scope.handleChange
      })));
    }

    if (template.type === "select") {
      formContent.push( /*#__PURE__*/React.createElement("div", {
        className: "col " + template.class,
        key: template.id + '00s'
      }, /*#__PURE__*/React.createElement(Select, {
        key: template.id,
        id: template.id,
        label: template.labelName,
        name: template.name,
        type: template.type,
        value: scope.state[template.name],
        isValid: template.isValid,
        options: template.options,
        onChange: scope.handleChange
      })));
    }

    if (template.type === "checkbox" || template.type === "radio") {
      formContent.push( /*#__PURE__*/React.createElement("div", {
        className: "col " + template.class,
        key: template.id + '00s'
      }, /*#__PURE__*/React.createElement(CheckBox, {
        key: template.id,
        id: template.id,
        label: template.labelName,
        name: template.name,
        type: template.type,
        value: scope.state[template.name],
        isValid: template.isValid,
        options: template.options,
        onChange: scope.handleChange
      })));
    }

    if (template.type === "datepicker" || template.type === "timepicker") {
      formContent.push( /*#__PURE__*/React.createElement("div", {
        className: "col " + template.class,
        key: template.id + '00dt'
      }, /*#__PURE__*/React.createElement(DateTime, {
        key: template.id,
        id: template.id,
        label: template.labelName,
        name: template.name,
        value: scope.state[template.name],
        type: template.type,
        isValid: template.isValid,
        onChange: scope.handleChange
      })));
    }

    if (template.type === "label") {
      formContent.push( /*#__PURE__*/React.createElement("div", {
        className: "col " + template.class,
        key: template.id + '00lbl'
      }, /*#__PURE__*/React.createElement(Form.Group, {
        controlId: template.id
      }, /*#__PURE__*/React.createElement(Form.Label, null, template.labelName + " :", "\xA0\xA0"), /*#__PURE__*/React.createElement(Form.Label, null, template.value))));
    }

    if (template.type === "submit" || template.type === "button") {
      formContent.push( /*#__PURE__*/React.createElement("div", {
        className: "col " + template.class,
        key: template.id + '02'
      }, /*#__PURE__*/React.createElement(Form.Group, {
        controlId: template.id
      }, /*#__PURE__*/React.createElement(Button, {
        variant: "primary",
        type: template.type
      }, template.value))));
    }

    return formContent;
  }
  /*
   * template : form elements
   * formContent : array variable to push the form elements
   */


  async constructTableRowElements(template, formContent, scope) {
    if (template.type === "text" || template.type === "password" || template.type === "email") {
      formContent.push( /*#__PURE__*/React.createElement("td", {
        className: "col " + template.class,
        key: template.id + '00t'
      }, /*#__PURE__*/React.createElement(TextBox, {
        key: template.id,
        id: template.id,
        type: template.type,
        placeholder: template.placeholder,
        name: template.name,
        value: scope.state[template.name],
        label: template.labelName,
        onChange: scope.handleChange
      })));
    }

    if (template.type === "select") {
      formContent.push( /*#__PURE__*/React.createElement("td", {
        className: "col " + template.class,
        key: template.id + '00s'
      }, /*#__PURE__*/React.createElement(Select, {
        key: template.id,
        id: template.id,
        label: template.labelName,
        name: template.name,
        type: template.type,
        value: scope.state[template.name],
        isValid: template.isValid,
        options: template.options,
        onChange: scope.handleChange
      })));
    }

    if (template.type === "checkbox" || template.type === "radio") {
      formContent.push( /*#__PURE__*/React.createElement("td", {
        className: "col " + template.class,
        key: template.id + '00s'
      }, /*#__PURE__*/React.createElement(CheckBox, {
        key: template.id,
        id: template.id,
        label: template.labelName,
        name: template.name,
        type: template.type,
        value: scope.state[template.name],
        isValid: template.isValid,
        options: template.options,
        onChange: scope.handleChange
      })));
    }

    if (template.type === "datepicker" || template.type === "timepicker") {
      formContent.push( /*#__PURE__*/React.createElement("td", {
        className: "col " + template.class,
        key: template.id + '00dt'
      }, /*#__PURE__*/React.createElement(DateTime, {
        key: template.id,
        id: template.id,
        label: template.labelName,
        name: template.name,
        value: scope.state[template.name],
        type: template.type,
        isValid: template.isValid,
        onChange: scope.handleChange
      })));
    }

    if (template.type === "label") {
      formContent.push( /*#__PURE__*/React.createElement("td", {
        className: "col " + template.class,
        key: template.id + '00lbl'
      }, /*#__PURE__*/React.createElement(Form.Group, {
        controlId: template.id
      }, /*#__PURE__*/React.createElement(Form.Label, null, template.labelName + " :", "\xA0\xA0"), /*#__PURE__*/React.createElement(Form.Label, null, template.value))));
    }

    if (template.type === "submit" || template.type === "button") {
      formContent.push( /*#__PURE__*/React.createElement("td", {
        className: "col " + template.class,
        key: template.id + '02'
      }, /*#__PURE__*/React.createElement(Form.Group, {
        controlId: template.id
      }, /*#__PURE__*/React.createElement(Button, {
        variant: "primary",
        type: template.type
      }, template.value))));
    }

    return formContent;
  }

  async loadInputElement(template) {
    return /*#__PURE__*/React.createElement("td", null, "Rows" + template.name);
  }

}

export default UtilsService;