<?php
/*
 * Page Name: Add New
 */

use FlexiMenu\Admin\CreateFields;
use FlexiMenu\Admin\Settings;
use FlexiMenu\WOWP_Plugin;

defined( 'ABSPATH' ) || exit;

$options = Settings::get_options();

$title = $options['title'] ?? '';
$id    = $options['id'] ?? '';

if ( ! isset( $options['live_preview'] ) ) {
	$builder_open = ' open';
} elseif ( ! empty( $options['live_preview'] ) ) {
	$builder_open = ' open';
} else {
	$builder_open = '';
}

?>
<form action="" id="wpie-settings" class="wpie-settings__wrapper" method="post">

    <div class="wpie-settings__main">

        <div class="wpie-field">
            <label class="wpie-field__label">
                <span class="screen-reader-text">
                    <?php esc_html_e( 'Enter title here', 'flexi-menu' ); ?></span>
                <input type="text" name="title" size="30" value="<?php
				echo esc_attr( $title ); ?>" id="title" placeholder="<?php
				esc_attr_e( 'Add title', 'flexi-menu' ); ?>">
            </label>
        </div>

        <details class="wpie-item is-builder"<?php echo esc_attr( $builder_open ); ?>>
            <input type="hidden" name="live_preview" class="wpie-item__toggle" value="1">
            <summary class="wpie-item_heading">
                <h3>
                    <span class="wpie-icon wpie_icon-eye-open"></span>
                    <span class="wpie-icon wpie_icon-eye-closed"></span>
				    <?php esc_html_e( 'Live preview', 'flexi-menu'  ); ?>
                </h3>
                <span class="wpie-item_heading_toogle">
                    <span class="wpie-icon wpie_icon-chevron-down"></span>
                <span class="wpie-icon wpie_icon-chevron-up "></span>
                </span>
            </summary>

            <div class="wpie-live-preview" id="live-builder">
                <div class="fleximenu-box -active">
                    <ul class="fleximenu">
                    </ul>
                </div>
            </div>

        </details>


		<?php
		Settings::init(); ?>

    </div>

    <div class="wpie-settings__sidebar">
		<?php
		require_once WOWP_Plugin::dir() . 'admin/settings/sidebar.php'; ?>
    </div>

    <input type="hidden" name="tool_id" value="<?php
	echo absint( $id ); ?>" id="tool_id"/>
    <input type="hidden" name="item_time" value="<?php
	echo esc_attr( time() ); ?>"/>
	<?php
	wp_nonce_field( WOWP_Plugin::PREFIX . '_nonce', WOWP_Plugin::PREFIX . '_settings' ); ?>
</form>

<?php

$text = __( 'Item Saving', 'flexi-menu' );
echo '<div class="wpie-notice notice notice-success">' . esc_html( $text ) . '</div>';
