<?php

class RmCf7Element extends OxyEl {

    function init() {
        // Do some initial things here.
    }

    function afterInit() {

    }

    function name() {
        return 'RM CF7';
    }
    
    function slug() {
        return "rm-cf7-element";
    }

    function icon() {
        return CT_FW_URI . '/toolbar/UI/oxygen-icons/add-icons/image.svg';
    }

    function button_place() {
        return "other";
    }

    function button_priority() {
        return '';
    }

    
    function render($options, $defaults, $content) {
        $form_id        = (isset($options['form_id'])) ? rm_oxy_fetchDynamicData( $options['form_id'] ) : 0;
        $default_form_id = (isset($options['default_form_id'])) ? rm_oxy_fetchDynamicData( $options['default_form_id'] ) : 0;

        $form_id = (! $form_id || get_post_status( $form_id ) != 'publish') ? $default_form_id : $form_id;
        
        echo do_shortcode( '[contact-form-7 id="'. $form_id .'"]' );

        ?>
        
        <?php
    }

    function controls() {

        $this->addOptionControl(
            array(
                "type" => 'textfield',
                "name" => __('Form id'),
                "slug" => 'form_id',
                "default" => '',
                'shortcode'	=> true,
            )
        )->rebuildElementOnChange()
        ->setParam('dynamicdatacode', rm_file_with_data("ISTCF7FormId", "", ""));
        
        $this->addOptionControl(
            array(
                "type" => 'textfield',
                "name" => __('Default Form id'),
                "slug" => 'default_form_id',
                "default" => '',
                'shortcode'	=> true,
            )
        )->rebuildElementOnChange()
        ->setParam('dynamicdatacode', rm_file_with_data("ISTCF7DefaultFormId", "", ""));
        
   
    }

}


new RmCf7Element();

