this.primevue = this.primevue || {};
this.primevue.formitem = (function (vue, utils) {
  'use strict';

  var script = {
       name: 'FormItem',
       props: {
          editor:{
               type:String,
               default:null
            },

           field:{
              type:String,
              default:null
           },

           colType:{
              type:String,
              default: null
           },

           initial:{
              type:null,
              default: null
           },

           label:{
              type:String,
              default:''
           },

           labelWidth: {
               type: [String, Number],
               default: null,
           },
           suffix:
           {
              type:String,
              default: ''
           },

           required:{
               type:Boolean,
               default:false
           },

           disabled:{
               type:[Boolean,String,Function],
               default:null
           },

           readonly:{
               type:[Boolean,String,Function],
               default:null
           },

           error: {
               type: String,
               default: '',
           },

          align:{
              type:String,
              default:null
          },

           className:{
              type:String,
              default:null
           },
           style: {
              type: null,
              default: null
          },

           cols:{
              type: [Number,String] ,
              default:0 
           },

           offset:{
              type: [Number,String],
              default:0 
           }

       },

       inject:{
           formContext: "Form" 
       },

       provide(){
          return {
              "FormItem": vue.computed(()=>{
                  return { ...this.$props}
              })
          }
       },

       data() {
           return {
               
           };
       },

       methods: {
          onUpdateModelValue(value){
             if(this.formContext)
                  this.formContext.onItemChange({ rowData: this.formContext.primaryData , field:this.field , value});
           },
       },
       
       computed:{
          primaryData(){
              const data= (this.formContext) ? this.formContext.primaryData  : null;
              
              return (data ) ? data : {};
          },

          containerClass() {
              const colClass = (this.cols>0 ) ?'col-'+this.cols : null;
              const offsetClass= (this.offset>0 ) ?'col-offset-'+this.offset : null;

              return [colClass,offsetClass,'form-item' ];
          },
          containerStyle(){
             let style = this.style;

              if((typeof style)==='cls')
                 style = bodyStyle(this.primaryData, this.field);

              return style;
          },

          showLabel(){
              const tagName =this.editor;
              
             return ( !this.label || tagName==='Checkbox' || tagName==='RadioButton' || tagName==='TriStateCheckbox') ? false :true;
          },

          labelClass(){
              return ["form-item-label",
              {
                  'required':this.required
              }]
          },

          labelWidthStyle(){
            
              let width =  this.labelWidth? this.labelWidth :( (this.formContext && this.formContext.labelWidth)? this.formContext.labelWidth: null) ;

              if(!width)
                  return null;

              return [ `width: ${width}` ];
        
          },

          isDisabled(){
              if(this.formContext && (this.formContext.disabled || !this.formContext.primaryData) )
                  return true;

             const primaryData =this.primaryData;

             if(this.disabled===null || this.disabled===undefined || this.disabled==='' )
                  return false;
             else if( ( typeof this.disabled) ==='boolean')
                 return this.disabled;
              else if( ( typeof this.disabled)==='function' &&  primaryData )
                  return this.disabled(primaryData, this.field );
              else if(this.disabled ==='notnew' && primaryData){
                  const status=primaryData['rowStatus'];

                  return ( status ===utils.RowStatus.New || status===utils.RowStatus.NewModified)? false : true;
              }
             
             return  ( this.disabled==='1'  ) ? true: false;
          },

          isReadonly(){
              if(this.formContext && this.formContext.readonly)
                  return true;

              const primaryData =this.primaryData;

              if(this.readonly===null || this.readonly===undefined || this.readonly==='' )
                  return false;
             else if( ( typeof this.readonly) ==='boolean')
                 return this.readonly;
              else if(( typeof this.readonly) ==='function' && primaryData)
                  return this.readonly(primaryData, this.field);
              else if(this.readonly==='notnew' && primaryData ){
                  const status=primaryData['rowStatus'];

                  return ( status ===utils.RowStatus.New || status===utils.RowStatus.NewModified)? false : true;
              }
             
             return  ( this.readonly==='1'  ) ? true: false;
          }
       },
      
   };

  const _hoisted_1 = ["data-field"];
  const _hoisted_2 = {
    key: 0,
    class: "form-item-suffix"
  };

  function render(_ctx, _cache, $props, $setup, $data, $options) {
    return (vue.openBlock(), vue.createElementBlock("div", {
      style: vue.normalizeStyle($options.containerStyle),
      class: vue.normalizeClass($options.containerClass),
      "data-field": $props.field
    }, [
      vue.renderSlot(_ctx.$slots, "label", {}, () => [
        ($options.showLabel)
          ? (vue.openBlock(), vue.createElementBlock("label", {
              key: 0,
              class: vue.normalizeClass($options.labelClass),
              style: vue.normalizeStyle($options.labelWidthStyle)
            }, vue.toDisplayString($props.label), 7 /* TEXT, CLASS, STYLE */))
          : vue.createCommentVNode("v-if", true)
      ]),
      vue.renderSlot(_ctx.$slots, "default", {
        primaryData: $options.primaryData,
        field: $props.field,
        disabled: $options.isDisabled,
        readonly: $options.isReadonly,
        "onUpdate:modelValue": _cache[0] || (_cache[0] = (...args) => ($options.onUpdateModelValue && $options.onUpdateModelValue(...args)))
      }, () => [
        ($props.field && $props.editor)
          ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent($props.editor), vue.mergeProps({
              key: 0,
              modelValue: $options.primaryData[$props.field],
              "onUpdate:modelValue": _cache[1] || (_cache[1] = $event => (($options.primaryData[$props.field]) = $event)),
              class: [$props.className, { 'form-item-content': $props.editor!=='InputSwitch' } ]
            }, _ctx.$attrs, {
              align: $props.align,
              label: $props.label,
              disabled: $options.isDisabled,
              readonly: $options.isReadonly,
              "onUpdate:modelValue": $options.onUpdateModelValue
            }), null, 16 /* FULL_PROPS */, ["modelValue", "class", "align", "label", "disabled", "readonly", "onUpdate:modelValue"]))
          : vue.createCommentVNode("v-if", true)
      ]),
      vue.renderSlot(_ctx.$slots, "suffix", {}, () => [
        ($props.suffix!=''  )
          ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_2, vue.toDisplayString($props.suffix), 1 /* TEXT */))
          : vue.createCommentVNode("v-if", true)
      ])
    ], 14 /* CLASS, STYLE, PROPS */, _hoisted_1))
  }

  script.render = render;
  script.__file = "components/lib/formitem/FormItem.vue";

  return script;

})(Vue, primevue.utils);
