<?php
if (!defined('WPINC')) {
    die('Closed');
}?>
<script>
jQuery(document).ready(function() {
  jQuery(window).keydown(function(event){
    if(event.keyCode == 13) {
      event.preventDefault();
      return false;
    }
  });
});
jQuery(document).ready(function(e){
    jQuery(document).on('click', 'button.rm-form-template-btn',function(event) {
        var temp = jQuery(this).data('tempid');
        var temp_title = jQuery(this).data('title');
        var temp_submit = jQuery(this).data('submit');
        var temp_submitalign = jQuery(this).data('submitalign');
        var temp_type = jQuery(this).data('type');
        if(temp_type){
            jQuery('#temp_type').val(temp_type);
        }
        jQuery('#form_name_template').val(temp_title);
        jQuery('.form_submit_btn_label').val(temp_submit);
        jQuery('.form_btn_align').val(temp_submitalign);
        jQuery('#template_type').val(temp);
        if(temp.includes('r')){
            jQuery('#temp_form_type').val('rm_reg_form');  
        }
        else{
            jQuery('#temp_form_type').val('rm_contact_form');
        }
        jQuery('#rm_submit_btn_template').click();
    });
    jQuery(document).ready(function(){
        jQuery("#rm-input-filterTemplate").on("keyup", function() {
          var value = jQuery(this).val().toLowerCase();
          jQuery(".form_temp li").filter(function() {
            jQuery(this).toggle(jQuery(this).text().toLowerCase().indexOf(value) > -1)
          });
        });
    });
});

</script>
<form action="" id="rm_form_add_new_form_template" method="post" class="form-horizontal">
    <input type="submit" value="<?php _e("Save",'registrationmagic-addon') ?>" name="submit" id="rm_submit_btn_template" style="display: none;">
    <input type="hidden" name="rm_slug" value="rm_form_add_new_form_template" id='rm_form_template_slug'>
    <input type="hidden" name="form_type" value="rm_reg_form" id="temp_form_type"/>
    <input type="hidden" name="type" value="basic" id="temp_type"/>
    <input type="hidden" value="Template" name="form_name" id="form_name_template" />
    <input type="hidden" name="form_submit_btn_label" value="SEND" class="form_submit_btn_label">
    <input type="hidden" name="form_btn_align" value="left" class="form_btn_align">
    <input type="hidden" name="template_type" value="c1" id="template_type">
    
    <div class="rm-templates_list">
        <div class="rm-templates-type-tabs">
            <div class="templates-tabs-panel">
                <div class="rm-template-filter">
                    <div class="rm-temp-filter-input">
                        <input id="rm-input-filterTemplate" type="text" placeholder="Search Templates">
                        <span class="material-icons">search</span>
                    </div>
                    <div class="rm-temp-filter-suggestion">
                        <ul>
                            <li><span class="material-icons">person</span><label>= Creates User Accounts</label></li>
                            <li><span class="material-icons">auto_stories</span><label> = Multi-page Forms</label></li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="templates-body-panel">
                <div class="template-body tt-panel-active">
                    <ul class="form_temp">
                        <?php foreach($data->templates as $template){
                            if($template['ver']=='standard'){
                            ?>
                            <li class="form-contact form_temp_bullet">
                                <div class="rm-temp-card">
                                    <div class="rm-temp-header">
                                        <h3 class="rm-temp-header-title"><?php echo $template['title'];?></h3>
                                        <div class="rm-template-label-icon">
                                            <?php 
                                            if($template['create_user']){
                                                echo '<span class="material-icons">person</span>';
                                            }
                                            if($template['multipage']){
                                                echo '<span class="material-icons">auto_stories</span>';
                                            }
                                            ?>
                                        </div>
                                        <p><?php echo $template['description'];?></p>
                                        <div class="rm-form-template-link"><a href="#" class="rm-form-template-demo">Live Preview<span class="material-icons"> launch </span></a></div>
                                    </div>
                                    <div class="rm-temp-footer">
                                        <button class="rm-form-template-btn" data-tempid="<?php echo $template['id'];?>" data-type="basic" data-title="<?php echo $template['title'];?>" data-submit="Submit" data-submitalign="center" type="button"><?php _e('Use Template','registrationmagic-addon');?></button>                                
                                    </div>
                                </div>
                            </li>
                            <?php
                            }
                            elseif($template['ver']=='premium'){
                            ?>
                            <li class="form-contact form_temp_bullet">
                            <div class="rm-temp-card">
                                <div class="rm-temp-header">
                                    <h3 class="rm-temp-header-title"><?php echo $template['title'];?></h3>
                                    <div class="rm-template-label-icon">
                                        <?php 
                                            if($template['create_user']){
                                                echo '<span class="material-icons">person</span>';
                                            }
                                            if($template['multipage']){
                                                echo '<span class="material-icons">auto_stories</span>';
                                            }
                                        ?>
                                    </div>    
                                   <p><?php echo $template['description'];?></p>
                                    <div class="rm-form-template-link"><a href="#" class="rm-form-template-demo">Live Preview<span class="material-icons"> launch </span></a></div>
                                </div>
                                <div class="rm-temp-footer">
                                    <button class="rm-form-template-btn" data-tempid="<?php echo $template['id'];?>" data-type="addon" data-title="<?php echo $template['title'];?>" data-submit="Submit" data-submitalign="center" type="button"><?php _e('Use Template', 'registrationmagic-addon'); ?></button>
                                </div>
                            </div>
                        </li>
                            <?php
                            }
                        }?>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</form>