<?php
/*
 * Page Name: Menu
 */

use FlexiMenu\Admin\CreateFields;

defined( 'ABSPATH' ) || exit;

$page_opt = include( 'options/1.menu.php' );

$field = new CreateFields( $options, $page_opt );

$count  = ( ! empty( $options['item']['type'] ) ) ? count( $options['item']['type'] ) : '0';
$prefix = 'item-';

?>
    <div class="wpie-items__list" id="wpie-items-list">
		<?php
		if ( $count > 0 ) :
			for ( $i = 0; $i < $count; $i ++ ):
				$order = $i + 1;
				$status = ! empty( $options['item_status'][ $i ] ) ? 1 : 0;
				$open = ! empty( $status ) ? ' open' : '';

				$item_parent = $options['item_parent'][ $i ] ?? 0;
				$item_class  = '';
				if ( absint( $item_parent ) === 1 ) {
					$item_class = ' shifted-right';
				} elseif ( absint( $item_parent ) === 2 ) {
					$item_class = ' shifted-further';
				}

				?>
                <details class="wpie-item  menu-item<?php echo esc_attr( $item_class ); ?>"<?php
				echo esc_attr( $open ); ?>>
                    <input type="hidden" name="param[item_status][]" class="wpie-item__toggle"
                           value="<?php echo absint( $status ); ?>">
                    <input type="hidden" name="param[item_parent][]" class="wpie-item__parent"
                           value="<?php echo esc_attr( $item_parent ); ?>">
                    <summary class="wpie-item_heading">
                        <span class="wpie-item_heading_icon"></span>
                        <span class="wpie-item_heading_label"></span>
                        <span class="wpie-item_heading_type"></span>
                        <span class="wpie-icon wpie_icon-copy"></span>
                        <span class="wpie-icon wpie_icon-chevron-expand-y"></span>
                        <span class="wpie-icon wpie_icon-trash"></span>
                        <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-item_content">

                        <div class="wpie-fieldset">
                            <div class="wpie-fields">
								<?php $field->create( $prefix . 'label', $i ); ?>
                            </div>
                        </div>

                        <div class="wpie-tabs-wrapper">

                            <div class="wpie-tabs-link">
                                <a class="wpie-tab__link is-active"><?php esc_html_e( 'Type', 'flexi-menu' ); ?></a>
                                <a class="wpie-tab__link"><?php esc_html_e( 'Icon', 'flexi-menu' ); ?></a>
                                <a class="wpie-tab__link"><?php esc_html_e( 'Attributes', 'flexi-menu' ); ?></a>
                            </div>

                            <div class="wpie-tab-settings is-active">
                                <div class="wpie-fieldset">
                                    <div class="wpie-fields">
										<?php $field->create( $prefix . 'type', $i ); ?>
										<?php $field->create( $prefix . 'link', $i ); ?>
										<?php $field->create( $prefix . '_blank', $i ); ?>
                                    </div>
                                </div>
                            </div>

                            <div class="wpie-tab-settings">
                                <div class="wpie-fieldset">
                                    <div class="wpie-legend">Icon</div>
                                    <div class="wpie-fields">
										<?php $field->create( $prefix . 'icon_type', $i ); ?>
										<?php $field->create( $prefix . 'icon', $i ); ?>
                                    </div>
                                </div>
                            </div>

                            <div class="wpie-tab-settings">
                                <div class="wpie-fieldset">
                                    <div class="wpie-fields">
										<?php $field->create( $prefix . 'attribute_id', $i ); ?>
										<?php $field->create( $prefix . 'attribute_class', $i ); ?>
										<?php $field->create( $prefix . 'attribute_rel', $i ); ?>
                                    </div>

                                </div>
                            </div>

                        </div>
                    </div>

                </details>
			<?php
			endfor; endif; ?>

        <hr class="wpie-buttons__hr">
        <div class="wpie-fields">
            <button class="button button-primary wpie-add-button" type="button">
				<?php
				esc_html_e( 'Add New', 'flexi-menu' ); ?>
            </button>
        </div>

    </div>


    <template id="template-button">
        <details class="wpie-item menu-item" open>
            <input type="hidden" name="item_open[]" class="wpie-item__toggle" value="1">
            <input type="hidden" name="param[item_parent][]" class="wpie-item__parent" value="0">
            <summary class="wpie-item_heading">
                <span class="wpie-item_heading_icon"></span>
                <span class="wpie-item_heading_label"></span>
                <span class="wpie-item_heading_type"></span>
                <span class="wpie-icon wpie_icon-copy"></span>
                <span class="wpie-icon wpie_icon-chevron-expand-y"></span>
                <span class="wpie-icon wpie_icon-trash"></span>
                <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-item_content">

                <div class="wpie-fieldset">
                    <div class="wpie-fields">
						<?php $field->create( $prefix . 'label', - 1 ); ?>
                    </div>
                </div>

                <div class="wpie-tabs-wrapper">

                    <div class="wpie-tabs-link">
                        <a class="wpie-tab__link is-active"><?php esc_html_e( 'Type', 'flexi-menu' ); ?></a>
                        <a class="wpie-tab__link"><?php esc_html_e( 'Icon', 'flexi-menu' ); ?></a>
                        <a class="wpie-tab__link"><?php esc_html_e( 'Attributes', 'flexi-menu' ); ?></a>
                    </div>

                    <div class="wpie-tab-settings is-active">
                        <div class="wpie-fieldset">
                            <div class="wpie-fields">
								<?php $field->create( $prefix . 'type', - 1 ); ?>
								<?php $field->create( $prefix . 'link', - 1 ); ?>
								<?php $field->create( $prefix . '_blank', - 1 ); ?>
                            </div>
                        </div>
                    </div>

                    <div class="wpie-tab-settings">
                        <div class="wpie-fieldset">
                            <div class="wpie-legend">Icon</div>
                            <div class="wpie-fields">
								<?php $field->create( $prefix . 'icon_type', - 1 ); ?>
								<?php $field->create( $prefix . 'icon', - 1 ); ?>
                            </div>
                        </div>
                    </div>

                    <div class="wpie-tab-settings">
                        <div class="wpie-fieldset">
                            <div class="wpie-fields">
								<?php $field->create( $prefix . 'attribute_id', - 1 ); ?>
								<?php $field->create( $prefix . 'attribute_class', - 1 ); ?>
								<?php $field->create( $prefix . 'attribute_rel', - 1 ); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </details>
    </template>

<?php
