<?php get_header();

$nft_single_meta = get_post_meta( get_the_ID(), 'ethrik_nft_single_meta', true );

if(array_key_exists( 'nft-owner', $nft_single_meta )) {
    $nft_owner_name = $nft_single_meta['nft-owner'];
} else {
    $nft_owner_name = '';
}


if(array_key_exists( 'nft-owner-thumb', $nft_single_meta )) {
    $nft_owner_thumb = $nft_single_meta['nft-owner-thumb'];
} else {
    $nft_owner_thumb = '';
}

if(array_key_exists( 'nft-ends-text', $nft_single_meta )) {
    $nft_ends_text = $nft_single_meta['nft-ends-text'];
} else {
    $nft_ends_text = '';
}

if(array_key_exists( 'nft-price-eth', $nft_single_meta )) {
    $nft_price_eth = $nft_single_meta['nft-price-eth'];
} else {
    $nft_price_eth = '';
}
    
if(array_key_exists( 'nft-price-usd', $nft_single_meta )) {
    $nft_price_usd = $nft_single_meta['nft-price-usd'];
} else {
    $nft_price_usd = '';
}
  
if(array_key_exists( 'nft-buy-btn-text', $nft_single_meta )) {
    $nft_buy_btn_text = $nft_single_meta['nft-buy-btn-text'];
} else {
    $nft_buy_btn_text = '';
}

if(array_key_exists( 'nft-buy-btn-link', $nft_single_meta )) {
    $nft_buy_btn_link = $nft_single_meta['nft-buy-btn-link'];
} else {
    $nft_buy_btn_link = '';
}

if(array_key_exists( 'nft-offer-btn-text', $nft_single_meta )) {
    $nft_offer_btn_text = $nft_single_meta['nft-offer-btn-text'];
} else {
    $nft_offer_btn_text = '';
}

if(array_key_exists( 'nft-offer-btn-link', $nft_single_meta )) {
    $nft_offer_btn_link = $nft_single_meta['nft-offer-btn-link'];
} else {
    $nft_offer_btn_link = '';
}

if(array_key_exists( 'nft-high-bid', $nft_single_meta )) {
    $nft_high_bid = $nft_single_meta['nft-high-bid'];
} else {
    $nft_high_bid = '';
}

$nft_details_page_title_show = ethrik_get_option('nft_details_page_title_show', true);
$nft_details_title_text = ethrik_get_option('nft_details_title_text');
$brdcrmb_nft_item_text = ethrik_get_option('brdcrmb_nft_item_text');

$sale_end_show = ethrik_get_option('sale_end_show', true);
$show_crnt_prc = ethrik_get_option('show_crnt_prc', true);
$show_eth_prc = ethrik_get_option('show_eth_prc', true);
$show_usd_prc = ethrik_get_option('show_usd_prc', true);
$show_buy_btn = ethrik_get_option('show_buy_btn', true);
$show_offer_btn = ethrik_get_option('show_offer_btn', true);
$show_highest_bid = ethrik_get_option('show_highest_bid', true);

?>

<!-- Breadcrumb -->
<div class="theme-breadcrumb__Wrapper theme-breacrumb-area">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-12">

                <?php if( $nft_details_page_title_show == true ) : ?>
                    <h1 class="theme-breacrumb-title">
                        <?php esc_html_e($nft_details_title_text, 'ethrik'); ?>
                    </h1>
                <?php endif; ?>

                <div class="breadcrumb-nav-top">
                    <ul>
                        <li class="breadcrumb-home-menu"><a href="<?php echo esc_url(home_url('/')); ?>"><?php esc_html_e('Home', 'ethrik'); ?></a></li>
                        <li class="breadcrumb-item-menu"><a href="<?php echo esc_url(home_url('/')); ?>"><?php esc_html_e($brdcrmb_nft_item_text, 'ethrik'); ?></a></li>
                        <li class="breadcrumb-item-menu"><?php the_title(); ?></li>
                    </ul>
                </div>

            </div>
        </div>
    </div>
</div>
<!-- Breadcrumb End -->

<!-- NFT Details Area Start -->
<section id="nft-details" class="nft-details">
    <div class="container">
        <div class="row align-items-center">
            <div class="col-lg-6">
                <div class="nft-thumbnail">
                    <img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_title_attribute(); ?>">
                </div>
            </div>
            <div class="col-lg-6">
                <div class="nft-content">
                    <h1 class="product_title entry-title"><?php the_title(); ?></h1>

                    <div class="nft-owner-box">
                        <div class="nft-owner-title">
                            Current Owner
                        </div>
                        <div class="nft-owner-infos d-flex justify-content-start align-items-center">
                            <img src="<?php echo esc_attr( $nft_owner_thumb['url'] ); ?>" alt="<?php the_title_attribute(); ?>">
                            <h5><?php echo esc_html($nft_single_meta['nft-owner']); ?></h5>
                        </div>
                    </div>

                    <?php if( $sale_end_show == true ) : ?>
                        <div class="sale-ends-info-box">
                            <?php echo esc_html($nft_single_meta['nft-ends-text']); ?>
                        </div>
                    <?php endif; ?>

                    <?php if( $show_crnt_prc == true ) : ?>
                        <div class="nft-pricing-box">
                            <div class="current-price-title">Current Price</div>

                            <?php if( $show_eth_prc == true ) : ?>
                                <h1 class="current-price-eth"><?php echo esc_attr($nft_single_meta['nft-price-eth']); ?></h1>
                            <?php endif; ?>

                            <?php if( $show_usd_prc == true ) : ?>
                                <div class="current-price-dlr d-flex justify-content-start align-items-center">
                                    <img src="<?php echo ETHRIK_IMG.'/dollar-icon.svg'; ?>" alt="dollar-icon">
                                    <h2><?php echo esc_attr($nft_single_meta['nft-price-usd']); ?></h2>
                                </div>
                            <?php endif; ?>

                        </div>
                    <?php endif; ?>

                    <div class="nft-single-custom-btns">
                        <?php if( $show_buy_btn == true ) : ?>
                            <a href="<?php echo esc_url($nft_buy_btn_link['url']); ?>" target="_blank" class="nft-buy-now-btn"><?php echo esc_html($nft_buy_btn_text); ?></a>
                        <?php endif; ?>

                        <?php if( $show_offer_btn == true ) : ?>
                        <a href="<?php echo esc_url($nft_offer_btn_link['url']); ?>" target="_blank" class="nft-make-offer-btn"><?php echo esc_html($nft_offer_btn_text); ?></a>
                        <?php endif; ?>
                    </div>

                    <?php if( $show_highest_bid == true ) : ?>
                        <div class="nft-highest-bid-box">
                            Highest Bid <span><?php echo esc_attr($nft_single_meta['nft-high-bid']); ?></span>
                        </div>
                    <?php endif; ?>

                </div>
            </div>
            <div class="col-lg-12">
                <div class="nft-description">
                    <h2 class="desc-title">
                        description
                    </h2>
                    <?php the_content(); ?>
                </div>
            </div>
        </div>
    </div>
</section>
<!-- NFT Area End -->

<!-- More NFT Area Start -->
<section id="more-nft-items" class="more-nft-items pb-5 mb-5">
    <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <div class="related products">
                    <h2><?php esc_html_e('more NFT items', 'ethrik'); ?></h2>
                </div>
            </div>

            <?php
                $args = array(
                    'post_type' => 'nft',
                    'posts_per_page' => 4,
                );

                $query = new WP_Query($args);
                while( $query->have_posts() ){
                    $query->the_post();

                    $nft_single_item_meta = get_post_meta( get_the_ID(), 'ethrik_nft_single_meta', true );

                    if(array_key_exists( 'nft-price-usd', $nft_single_item_meta )) {
                        $nft_item_price_usd = $nft_single_item_meta['nft-price-usd'];
                    } else {
                        $nft_item_price_usd = '';
                    }
            ?>

            <!-- NFT Item Single -->
            <div class="col-lg-3 col-md-6 col-sm-12">
                <div class="nft-item-single">
                    <div class="product-media">
                        <a href="<?php the_permalink(); ?>">
                            <img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_title_attribute(); ?>">
                        </a>
                    </div>
                    <div class="product-content">
                        <h2 class="product-title">
                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                        </h2>
                        <span class="price"><?php echo esc_attr($nft_single_item_meta['nft-price-usd']); ?></span>
                    </div>
                </div>
            </div>

            <?php
                }
            ?>

        </div>
    </div>
</section>
<!-- More NFT Area End -->

<?php get_footer(); ?>