import Component  from '../component.js'
import CoUxFormControlInputText from './ux-form-control-inputText.js';
import CoUxFormControlTextArea from './ux-form-control-textArea.js';
import CoUxFormControlDatepicker from './ux-form-control-date-picker.js';
import CoUxFormControlDatetimepicker from './ux-form-control-date-time-picker.js';
import CoUxFormControlSelect from './ux-form-control-select.js';
import CoUxFormControlCheckbox from './ux-form-control-checkBox.js';
import CoUxFormControlInputNumber from './ux-form-control-inputNumber.js';
import CoUxFormControlRadio from './ux-form-control-radio.js';

export default class CoUxFormControl extends Component {
    constructor(parent) {
      let selector = 'ux-form-control';
      super(parent, selector);
      //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/core/src/lib/commons/ux-components/ux-form-control/ux-form-control.component.html?at=refs%2Fheads%2Fsupport%2F7.x
   }
   get dataE2E() {
      return this.currentPath + '//*[@data-e2e]';
   }
   // Input Text
   get inputTextCO() {
      return new CoUxFormControlInputText(this.currentPath);
   }
   // Text Area
   get textareaCO() {
      return new CoUxFormControlTextArea(this.currentPath);
   }
   // Datepicker
   get datepickerCO() {
      return new CoUxFormControlDatepicker(this.currentPath);
   }
   // Date Time Picker
   get dateTimePicker() {
      return new CoUxFormControlDatetimepicker(this.currentPath);
   }
   // Select
   get selectCO() {
      return new CoUxFormControlSelect(this.currentPath);
   }
   // Check Box
   get checkboxCO() {
      return new CoUxFormControlCheckbox(this.currentPath);
   }
   // Input Number
   get inputNumberCO() {
      return new CoUxFormControlInputNumber(this.currentPath);
   }
   // Radio
   get radioCO() {
      return new CoUxFormControlRadio(this.currentPath);
   }
   /**
   * @param input inputText: formcontrolname/placeholderlabel/maxlengthvalidationerrormessage/maxlength
   * @param input select: formcontrolname/placeholderlabel/selectkeyname/selectvaluename
   * @param input textarea: formcontrolname/placeholderlabel/maxlength/maxlengthvalidationerrormessage
   * @param input number: formcontrolname/maxlength/maxlengthvalidationerrormessage/decimalseparator/thousandseparator
   * @param input datepicker: formcontrolname/datepickeryearrange
   * @param input checkbox: formcontrolname
   * @param input radio: formcontrolname/formcontrolvalue/radiolabel/groupid
   * @type string
   */
    async getInputAtribute(input) {
      let value = await (await $(this.currentPath)).getAttribute(input);
      return value;
   }
   async isReadOnly() {
      let cl = await (await $(this.currentPath + '//*[@data-e2e ="ux-form-control-ro" or ' + 
      '@data-e2e ="ux-form-control-num-ro" or @data-e2e ="ux-form-control-cb-ro" or ' +
      '@data-e2e = "ux-form-control-ra-ro" or @data-e2e ="ux-form-control-dpicker-ro" or ' + 
      '@data-e2e ="ux-form-control-dtpicker-ro" or @data-e2e ="ux-form-control-sel-ro"]')).isExisting();
      if (cl) {
         return true;
      } else {
         return false;
      }
   } 
}


