<?php
/**
 * Wishlist manage template
 *
 * @author Your Inspiration Themes
 * @package YITH WooCommerce Wishlist
 * @version 3.0.0
 */

/**
 * Template variables:
 *
 * @var $page_title string Page title
 * @var $template_part string Template part currently being loaded (manage)
 * @var $user_wishlists YITH_WCWL_Wishlist[] Array of user wishlists
 * @var $show_number_of_items bool Whether to show number of items or not
 * @var $show_date_of_creation bool Whether to show date of creation or not
 * @var $show_download_as_pdf bool Whether to show download button or not
 * @var $show_rename_wishlist bool Whether to show rename button or not
 * @var $show_delete_wishlist bool Whether to show delete button or not
 */

if ( ! defined( 'YITH_WCWL' ) ) {
    exit;
} // Exit if accessed directly
?>

<table class="shop_table cart wishlist_table wishlist_manage_table responsive" cellspacing="0" >

    <?php $column_count = 2; ?>

    <thead>
        <tr>
            <th class="wishlist-name">
                <span class="nobr">
                    <?php echo apply_filters( 'yith_wcwl_wishlist_manage_name_heading', __( 'Wishlists', 'yith-woocommerce-wishlist' ) ) ?>
                </span>
            </th>

	        <?php if( $show_rename_wishlist ): $column_count ++; ?>
                <th class="wishlist-rename">
                    <span class="nobr">
                        <?php echo apply_filters( 'yith_wcwl_wishlist_manage_rename_heading', __( 'Rename', 'yith-woocommerce-wishlist' ) ) ?>
                    </span>
                </th>
	        <?php endif; ?>

            <th class="wishlist-privacy">
                <span class="nobr">
                    <?php echo apply_filters( 'yith_wcwl_wishlist_manage_privacy_heading', __( 'Privacy', 'yith-woocommerce-wishlist' ) ) ?>
                </span>
            </th>

            <?php if( $show_number_of_items ): $column_count ++; ?>
                <th class="wishlist-item-count">
                    <span class="nobr">
                        <?php echo apply_filters( 'yith_wcwl_wishlist_manage_number_of_items_heading', __( 'Count of items', 'yith-woocommerce-wishlist' ) ) ?>
                    </span>
                </th>
            <?php endif; ?>

            <?php if( $show_date_of_creation ): $column_count ++; ?>
                <th class="wishlist-dateadded">
                    <span class="nobr">
                        <?php echo apply_filters( 'yith_wcwl_wishlist_manage_dateadded_heading', __( 'Created on', 'yith-woocommerce-wishlist' ) ) ?>
                    </span>
                </th>
            <?php endif; ?>

            <?php if( $show_download_as_pdf ): $column_count ++; ?>
                <th class="wishlist-download">
                    <span class="nobr">
                        <?php echo apply_filters( 'yith_wcwl_wishlist_manage_download_heading', __( 'Download', 'yith-woocommerce-wishlist' ) ) ?>
                    </span>
                </th>
            <?php endif; ?>

            <?php if( $show_delete_wishlist ): $column_count ++; ?>
                <th class="wishlist-delete">
                    <span class="nobr">
                        <?php echo apply_filters( 'yith_wcwl_wishlist_manage_delete_heading', __( 'Delete', 'yith-woocommerce-wishlist' ) ) ?>
                    </span>
            </th>
            <?php endif; ?>
        </tr>
    </thead>
    <tbody>
        <?php
            if( ! empty( $user_wishlists ) ):
                foreach( $user_wishlists as $wishlist ):
                ?>

                <tr data-wishlist-id="<?php echo $wishlist->get_id() ?>">
                    <td class="wishlist-name">
                        <div class="wishlist-title">
                            <a title="<?php echo $wishlist->get_formatted_name() ?>" class="wishlist-anchor" href="<?php echo $wishlist->get_url() ?>">
                            <?php echo $wishlist->get_formatted_name() ?>
                        </a>
                        </div>

                        <div class="hidden-title-form">
                            <input type="text" value="<?php echo $wishlist->get_formatted_name() ?>" name="wishlist_options[<?php echo $wishlist->get_id() ?>][wishlist_name]"/>
                        </div>
                    </td>

	                <?php if( $show_rename_wishlist ): ?>
                        <td class="wishlist-rename">
                            <a href="#" class="show-title-form">
                                <i class="fa fa-pencil"></i>
                            </a>
                        </td>
	                <?php endif; ?>

                    <td class="wishlist-privacy">
                        <select name="wishlist_options[<?php echo $wishlist->get_id() ?>][wishlist_privacy]" class="wishlist-visibility selectBox">
                            <option value="0" class="public-visibility" <?php selected( $wishlist->get_privacy(), 0 ) ?> ><?php echo yith_wcwl_get_privacy_label( 0 ) ?></option>
                            <option value="1" class="shared-visibility" <?php selected( $wishlist->get_privacy(), 1 ) ?> ><?php echo yith_wcwl_get_privacy_label( 1 ) ?></option>
                            <option value="2" class="private-visibility" <?php selected( $wishlist->get_privacy(), 2 ) ?> ><?php echo yith_wcwl_get_privacy_label( 2 ) ?></option>
                        </select>
                    </td>

                    <?php if( $show_number_of_items ): ?>
                        <td class="wishlist-item-count">
                            <?php echo sprintf( __( '%d items', 'yith-woocommerce-wishlist' ), $wishlist->count_items() ) ?>
                        </td>
                    <?php endif; ?>

                    <?php if( $show_date_of_creation ): ?>
                        <td class="wishlist-dateadded">
                            <?php echo $wishlist->get_date_added_formatted() ?>
                        </td>
                    <?php endif; ?>

                    <?php if( $show_download_as_pdf ): ?>
                        <td class="wishlist-download">
                            <a class="wishlist-download" href="<?php echo $wishlist->get_download_url() ?>">
                                <i class="fa fa-download"></i>
                            </a>
                        </td>
                    <?php endif; ?>

                    <?php if( $show_delete_wishlist ): ?>
                        <td class="wishlist-delete">
                            <?php if( ! $wishlist->is_default() ): ?>
                                <a class="button wishlist-delete" onclick="return confirm('<?php _e( 'Are you sure you want to delete this wishlist?', 'yith-woocommerce-wishlist' ) ?>');" href="<?php echo esc_url( $wishlist->get_delete_url() ) ?>"><?php _e( 'Delete', 'yith-woocommerce-wishlist' ) ?></a>
                            <?php endif; ?>
                        </td>
                    <?php endif; ?>
                </tr>

                <?php
                endforeach;
            endif;
        ?>
    </tbody>
</table>