<?php defined('ABSPATH') or die("No script kiddies please!"); ?>
<?php
global $wpdb;

$wpfm_template_check_main_array = $this->global_template_display_condition_check();

$table_name = $wpdb->prefix . "wp_floating_menu_details";
$menu_detail = $wpdb->get_results("SELECT menu_display_setting_details FROM $table_name WHERE id=" . $_GET['id']);
foreach ($menu_detail as $row) {
    $id = $_GET['id'];
    $menu_design_settings = unserialize($row->menu_display_setting_details);
}

$table_name = $wpdb->prefix . "wp_floating_menu_custom_templates";
$custom_template_detail = $wpdb->get_results("SELECT * FROM $table_name ");

$current_custom_template_id = isset($menu_design_settings['menu_design']['custom_template_type']) && !empty($menu_design_settings['menu_design']['custom_template_type']) ? esc_attr($menu_design_settings['menu_design']['custom_template_type']) : '';
$get_template_data = $this->get_template_data($current_custom_template_id);
if (count($get_template_data) > 0) {
    foreach ($get_template_data as $row) {
        $row_template_details = maybe_unserialize($row->template_details);
        $custom_template_type = isset($row_template_details['custom_template']['menu_layout']) && !empty($row_template_details['custom_template']['menu_layout']) ? esc_attr($row_template_details['custom_template']['menu_layout']) : '';
    }
} else {
    $custom_template_type = '';
}
?>
<div class="wpfm-display-setting-wrapper">
    <div class="wpfm-setting-body">
        <div class="wpfm-menu-field-wrapper" id="wpfm-template-layout">
            <h4 class="wpfm-menu-field-header-text"><?php _e('Display Setting', 'wp-floating-menu-pro'); ?></h4>
            <p class="menu-field-info"><?php _e('Configure how you want to display menu.', 'wp-floating-menu-pro'); ?></p>
            <div class="wpfm-menu-display-setting" id="wpfm-menu-type-wrap">
                <label class="display-label-controller"><?php _e('Template style', 'wp-floating-menu-pro'); ?></label>
                <div class="wpfm-menu-inner-field">
                    <select name="menu_design[menu_template_style]" id="wpfm-menu-type">
                        <option value="buildin" <?php if (isset($menu_design_settings['menu_design']['menu_template_style']) && $menu_design_settings['menu_design']['menu_template_style'] == 'buildin') { ?>selected="selected"<?php } ?>><?php _e('Builtin Template', 'wp-floating-menu-pro'); ?></option>
                        <option value="custom-template" <?php if (isset($menu_design_settings['menu_design']['menu_template_style']) && $menu_design_settings['menu_design']['menu_template_style'] == 'custom-template') { ?>selected="selected"<?php } ?>><?php _e('Custom Template', 'wp-floating-menu-pro'); ?></option>
                    </select>
                </div>
            </div>
            <div class="wpfm-menu-display-setting" id="buildin-temple-listing" <?php if ((isset($menu_design_settings['menu_design']['menu_template_style']) && $menu_design_settings['menu_design']['menu_template_style'] == 'buildin') || $menu_design_settings['menu_design']['menu_template_style'] == '') { ?>style="display: block;" <?php } else { ?>style="display: none;"<?php } ?>>
                <label for="menu_design[template_number]" class="display-label-controller"><?php _e('Inbuilt Template', 'wp-floating-menu-pro'); ?></label>
                <div class="wpfm-menu-inner-field">
                    <select name="menu_design[template_number]" id="menu-template" class="menu-design template-dropdown" size="1" >
                        <?php for ($i = 1; $i <= 20; $i++) { ?>
                            <option class="wpfm-temp" value="template-<?php echo $i; ?>" <?php if (isset($menu_design_settings['menu_design']['template_number']) && $menu_design_settings['menu_design']['template_number'] == 'template-' . $i) { ?>selected="selected"<?php } ?>><?php
                                _e('Template', 'wp-floating-menu-pro');
                                echo " " . $i;
                                ?></option>
                        <?php } ?>
                    </select>
                </div>
                <div class="wpfm-template-demo" >
                    <?php for ($cnt = 1; $cnt <= 20; $cnt++) { ?>
                        <div class="wpfm-common" id="wpfm-temp-demo-<?php echo $cnt; ?>" <?php if ($cnt != 1) { ?>style="display:none;"<?php } ?>>
                            <?php if ($cnt > 13) { ?><span class="wpfm-new-templates wpfm-corner-ribbon wpfm-top-left"><?php _e('New Template', 'wp-floating-menu-pro'); ?></span><?php } ?>    
                            <p><?php _e('Template', 'wp-floating-menu-pro'); ?>  <?php echo $cnt; ?>  <?php _e('Preview', 'wp-floating-menu-pro'); ?></p>
                            <img src="<?php echo WPFM_PRO_IMAGE_DIR . '/template-' . $cnt . '_1.png' ?>"/>
                            <img src="<?php echo WPFM_PRO_IMAGE_DIR . '/template-' . $cnt . '_2.png' ?>"/>
                        </div>
                    <?php } ?> 
                </div>
            </div>

            <div class="wpfm-menu-display-setting" id="wpfm-custom-template-type" <?php if (isset($menu_design_settings['menu_design']['menu_template_style']) && $menu_design_settings['menu_design']['menu_template_style'] == 'custom-template') { ?>style="display: block;" <?php } else { ?>style="display: none;"<?php } ?>>
                <label class="display-label-controller"><?php _e('Custom Templates', 'wp-floating-menu-pro'); ?></label>
                <div class="wpfm-menu-inner-field">
                    <select name="menu_design[custom_template_type]" id="wpfm-custom-template">
                        <?php
                        if (count($custom_template_detail) > 0) {
                            foreach ($custom_template_detail as $row) {
                                ?>
                                <option value="<?php echo $row->id; ?>" <?php if (isset($menu_design_settings['menu_design']['custom_template_type']) && $menu_design_settings['menu_design']['custom_template_type'] == $row->id) { ?>selected="selected"<?php } ?>><?php echo esc_attr($row->template_name); ?></option>
                                <?php
                            }
                        } else {
                            ?>
                            <option value="null" disabled="disabled"><?php echo __('No Template Added Yet', 'wp-floating-menu-pro'); ?></option>
                        <?php } ?>
                    </select>
                </div>
            </div>

            <div class="wpfm-menu-display-setting" id="wpfm-menu-placement-wrap" <?php if ((isset($menu_design_settings['menu_design']['template_number']) && $menu_design_settings['menu_design']['menu_template_style'] == 'buildin' && in_array($menu_design_settings['menu_design']['template_number'], $wpfm_template_check_main_array['template_position_array_1'])) || (isset($menu_design_settings['menu_design']['menu_template_style']) && $menu_design_settings['menu_design']['menu_template_style'] == 'custom-template' && in_array($custom_template_type, $wpfm_template_check_main_array['template_position_array_1']))) {
                            ?>style="display: block;" <?php } else { ?>style="display: none;"<?php } ?>>
                <label>
                    <?php _e('Menu Bar Position', 'wp-floating-menu-pro'); ?>
                </label>
                <div class="wpfm-menu-inner-field">
                    <select name="menu_design[menu_placement]" id="wpfm-menu-placement">
                        <option value="top-left" <?php if (isset($menu_design_settings['menu_design']['menu_placement']) && $menu_design_settings['menu_design']['menu_placement'] == 'top-left') { ?>selected="selected"<?php } ?>><?php _e('Top Left', 'wp-floating-menu-pro'); ?></option>
                        <option value="left" <?php if (isset($menu_design_settings['menu_design']['menu_placement']) && $menu_design_settings['menu_design']['menu_placement'] == 'left') { ?>selected="selected"<?php } ?>><?php _e('Middle Left', 'wp-floating-menu-pro'); ?></option>
                        <option value="bottom-left" <?php if (isset($menu_design_settings['menu_design']['menu_placement']) && $menu_design_settings['menu_design']['menu_placement'] == 'bottom-left') { ?>selected="selected"<?php } ?>><?php _e('Bottom Left', 'wp-floating-menu-pro'); ?></option>
                        <option value="top-right" <?php if (isset($menu_design_settings['menu_design']['menu_placement']) && $menu_design_settings['menu_design']['menu_placement'] == 'top-right') { ?>selected="selected"<?php } ?>><?php _e('Top Right', 'wp-floating-menu-pro'); ?></option>
                        <option value="right" <?php if (isset($menu_design_settings['menu_design']['menu_placement']) && $menu_design_settings['menu_design']['menu_placement'] == 'right') { ?>selected="selected"<?php } ?>><?php _e('Middle Right', 'wp-floating-menu-pro'); ?></option>
                        <option value="bottom-right" <?php if (isset($menu_design_settings['menu_design']['menu_placement']) && $menu_design_settings['menu_design']['menu_placement'] == 'bottom-right') { ?>selected="selected"<?php } ?>><?php _e('Bottom Right', 'wp-floating-menu-pro'); ?></option>
                    </select>
                </div>
            </div>

            <div class="wpfm-menu-display-setting" id="wpfm-menu-placement-new-wrap" <?php if (isset($menu_design_settings['menu_design']['template_number']) && $menu_design_settings['menu_design']['menu_template_style'] == 'buildin' && in_array($menu_design_settings['menu_design']['template_number'], $wpfm_template_check_main_array['wpfm_position_check_array']) || (isset($menu_design_settings['menu_design']['menu_template_style']) && $menu_design_settings['menu_design']['menu_template_style'] == 'custom-template' && in_array($custom_template_type, $wpfm_template_check_main_array['wpfm_position_check_array']))) { ?>style="display: block;" <?php } else { ?>style="display: none;"<?php } ?>>
                <label><?php _e('Menu Bar Position', 'wp-floating-menu-pro'); ?></label>
                <div class="wpfm-menu-inner-field">
                    <select name="menu_design[cmenu_placement]" id="wpfm-menu-placement">
                        <option value="top-left" <?php if (isset($menu_design_settings['menu_design']['cmenu_placement']) && $menu_design_settings['menu_design']['cmenu_placement'] == 'top-left') { ?>selected="selected"<?php } ?>><?php _e('Top Left', 'wp-floating-menu-pro'); ?></option>
                        <option value="left" <?php if (isset($menu_design_settings['menu_design']['cmenu_placement']) && $menu_design_settings['menu_design']['cmenu_placement'] == 'left') { ?>selected="selected"<?php } ?>><?php _e('Middle Left', 'wp-floating-menu-pro'); ?></option> 
                        <option value="bottom-left" <?php if (isset($menu_design_settings['menu_design']['cmenu_placement']) && $menu_design_settings['menu_design']['cmenu_placement'] == 'bottom-left') { ?>selected="selected"<?php } ?>><?php _e('Bottom Left', 'wp-floating-menu-pro'); ?></option>
                        <option value="top-right" <?php if (isset($menu_design_settings['menu_design']['cmenu_placement']) && $menu_design_settings['menu_design']['cmenu_placement'] == 'top-right') { ?>selected="selected"<?php } ?>><?php _e('Top Right', 'wp-floating-menu-pro'); ?></option>
                        <option value="right" <?php if (isset($menu_design_settings['menu_design']['cmenu_placement']) && $menu_design_settings['menu_design']['cmenu_placement'] == 'right') { ?>selected="selected"<?php } ?>><?php _e('Middle Right', 'wp-floating-menu-pro'); ?></option> -->
                        <option value="bottom-right" <?php if (isset($menu_design_settings['menu_design']['cmenu_placement']) && $menu_design_settings['menu_design']['cmenu_placement'] == 'bottom-right') { ?>selected="selected"<?php } ?>><?php _e('Bottom Right', 'wp-floating-menu-pro'); ?></option>
                        <option value="bottom-center" <?php if (isset($menu_design_settings['menu_design']['cmenu_placement']) && $menu_design_settings['menu_design']['cmenu_placement'] == 'bottom-center') { ?>selected="selected"<?php } ?>><?php _e('Bottom Center', 'wp-floating-menu-pro'); ?></option>
                    </select>
                </div>
            </div>
            <div class="wpfm-menu-option-setting-field">
                <label class="menu-option-label-controller">
                    <h4><?php _e('Show Menu After Scroll Event', 'wp-floating-menu-pro'); ?></h4>
                </label>
                <label class="wpfm-switch">
                    <input type="checkbox" class="wpfm-checkbox" value="1" name="menu_design[show_menu_on_scroll]" <?php if (isset($menu_design_settings['menu_design']['show_menu_on_scroll']) && $menu_design_settings['menu_design']['show_menu_on_scroll'] == '1') { ?>checked="checked"<?php } ?>/>
                    <div class="wpfm-slider round"></div>
                </label>
                <div class="wpfm-tooltip-description">
                    <label class="wpfm-tt-description">
                        <?php _e('If checked, menu will be hidden initially until the scroll event.', 'wp-floating-menu-pro'); ?>
                    </label>
                </div>
            </div>
            <div class="wpfm-menu-display-setting">
                <label class="menu-option-label-controller">
                    <h4><?php _e('Show Menu After Scroll Event', 'wp-floating-menu-pro'); ?></h4>
                </label>
                <div class="wpfm-menu-inner-field">
                    <input type="number" name="menu_design[show_menu_scroll_event_value]" value="<?php echo isset($menu_design_settings['menu_design']['show_menu_scroll_event_value']) && !empty($menu_design_settings['menu_design']['show_menu_scroll_event_value']) ? esc_attr($menu_design_settings['menu_design']['show_menu_scroll_event_value']) : ''; ?>"/>
                </div>
                <p class="wpfm-tt-description">
                    <?php _e('Scroll value for menu to show. Default is 50', 'wp-floating-menu-pro'); ?>
                </p>
            </div>
        </div>
    </div><!-- .wpfm-setting-body -->
</div><!-- .wpfm-display-setting-wrapper -->