(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
    "use strict";
    
    Vue.component('wpcfto_tinymce', {
        props: ['fields', 'field_label', 'field_name', 'field_id', 'field_value', 'required'],
        data: function() {
          return {
            value: this.field_value || '', // initialize with prop value
            editorInitialized: false
          };
        },
        mounted: function() {
            const vm = this;
            // Initialize TinyMCE on the hidden textarea (with id = field_id)
            tinymce.init({
                selector: `#${this.field_id}`,
                height: 400,
                menubar: false,
                highlight_on_focus: false,
                plugins: 'advlist autolink lists link image charmap preview anchor searchreplace visualblocks code fullscreen insertdatetime table code help wordcount',
                toolbar: 'undo redo | formatselect | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | code wp_media | help',
                setup: function(editor) {
                    editor.on('init', function() {
                        // Set initial content from Vue data
                        editor.setContent(vm.value || '');
                        vm.editorInitialized = true;
                    });
                    editor.on('Change KeyUp', function() {
                        const content = editor.getContent();
                        vm.value = content;
                        vm.$emit('wpcfto-get-value', content);
                    });
                    editor.on('Paste', function (e) {
                      var clipboardData = e.clipboardData || e.originalEvent.clipboardData;
                      if (clipboardData && clipboardData.items) {
                        for (var i = 0; i < clipboardData.items.length; i++) {
                          var item = clipboardData.items[i];
                          if (item.type.indexOf('image') !== -1) {
                            var file = item.getAsFile();
                
                            // Upload the file to server here via AJAX
                            var formData = new FormData();
                            formData.append('file', file);
                            formData.append('action', 'upload_pasted_image');
                            formData.append('_wpnonce', wpcfto_tinymce.nonce);
                
                            fetch(ajaxurl, {
                              method: 'POST',
                              body: formData
                            })
                            .then(response => response.json())
                            .then(data => {
                              if (data.success) {
                                // Insert uploaded image URL into editor
                                editor.insertContent('<img src="' + data.data.url + '" />');
                              }
                            })
                            .catch(console.error);
                
                            // Prevent default paste to avoid blob URL insertion
                            e.preventDefault();
                            break;
                          }
                        }
                      }
                    });
                    editor.ui.registry.addButton('wp_media', {
                      icon: 'image',
                      tooltip: 'Insert Media',
                      onAction: function() {
                        // Open WordPress media modal
                        var frame = wp.media({
                          title: 'Select or Upload Media',
                          button: {
                            text: 'Insert into editor'
                          },
                          multiple: false
                        });
                
                        frame.on('select', function() {
                          var attachment = frame.state().get('selection').first().toJSON();
                          // Insert media HTML into TinyMCE editor
                          if (attachment.type === 'image') {
                            editor.insertContent('<img src="' + attachment.url + '" alt="' + (attachment.alt || '') + '" />');
                          } else if (attachment.type === 'video') {
                            editor.insertContent('<video controls src="' + attachment.url + '"></video>');
                          } else {
                            // For other media types, insert a link
                            editor.insertContent('<a href="' + attachment.url + '">' + attachment.filename + '</a>');
                          }
                        });
                
                        frame.open();
                      }
                    });
                },
                // Use your self-hosted skin path if needed, e.g.:
                skin_url: '/wp-content/plugins/formipay/vendor/wpcfto/metaboxes/assets/vendors/tinymce/skins/ui/oxide',
                content_css: '/wp-content/plugins/formipay/vendor/wpcfto/metaboxes/assets/vendors/tinymce/skins/content/default/content.min.css',
                license_key: 'gpl',
                branding: false,
            });
        },
        beforeDestroy() {
          // Properly remove TinyMCE instance when component is destroyed
          if (tinymce.get(this.field_id)) {
            tinymce.get(this.field_id).remove();
          }
        },
        methods: {
          enterHint: function(hint) {
            this.value += ' {{' + hint + '}}';
            if (tinymce.get(this.field_id)) {
              tinymce.get(this.field_id).setContent(this.value);
            }
          }
        },
        template: `
          <div class="wpcfto_generic_field wpcfto_generic_field_trumbowyg">
            <wpcfto_fields_aside_before
              :fields="fields"
              :field_label="field_label"
              :required="fields.required === true"
            ></wpcfto_fields_aside_before>
            <div class="wpcfto-field-content">
              <div class="hints" v-if="fields.hints && Object.keys(fields.hints).length">
                <span
                  v-for="(hint_text, hint_key) in fields.hints"
                  :key="hint_key"
                  @click="enterHint(hint_key)"
                  class="hint-token"
                >{{ hint_text }}</span>
              </div>
              <!-- Replace <vue-trumbowyg> with a simple textarea for TinyMCE -->
              <textarea
                :id="field_id"
                :name="field_name"
                :required="fields.required === true"
                style="width: 100%; min-height: 300px;"
              ></textarea>
              <!-- Hidden textarea for form submission and validation (optional) -->
              <textarea
                :name="field_name"
                :id="field_id + '_hidden'"
                v-model="value"
                :required="fields.required === true"
                style="display:none;"
              ></textarea>
            </div>
            <wpcfto_fields_aside_after :fields="fields"></wpcfto_fields_aside_after>
          </div>
        `,
        watch: {
          value: function(newValue) {
            this.$emit('wpcfto-get-value', newValue);
          }
        }
      });
      
    
//# sourceMappingURL=data:application/json;charset=utf-8;base64, 
    },{}]},{},[1])