/******/
(() => { // webpackBootstrap
    /*!************************************************!*\
      !*** ./src/assets/js/pages/landing-page-v2.js ***!
      \************************************************/
    $(function() {
        if (localStorage.getItem('logged_in') === 'true') {
            window.location.href = 'dashboard/wallet.html';
            return;
        }
        const API_URL = 'https://api.coingecko.com/api/v3/simple/price';
        const CRYPTO_IDS = 'bitcoin,ethereum,tether,binancecoin,ripple'; // Corresponding to BTC, ETH, USDT, BNB, XRP
        const VS_CURRENCY = 'usd';

        // Function to update crypto prices
        function updateCryptoPrices() {
            $.ajax({
                url: `${API_URL}?ids=${CRYPTO_IDS}&vs_currencies=${VS_CURRENCY}&include_market_cap=false&include_24hr_change=true`,
                method: 'GET',
                success: response => {
                    // Update Bitcoin price
                    $('#crypto-graph-item-graph__graph-1').closest('.crypto-graph-carousel__items').find('.crypto-graph-item--price-codename .crypto-graph-item__price').text(`USD ${response.bitcoin.usd.toFixed(2)}`);
                    $('#crypto-graph-item-graph__graph-1').closest('.crypto-graph-carousel__items').find('.crypto-graph-item-graph__inflution p').text(`${response.bitcoin.usd_24h_change.toFixed(2)}%`).parent().toggleClass('crypto-graph-item-graph__inflution--bullish', response.bitcoin.usd_24h_change > 0).toggleClass('crypto-graph-item-graph__inflution--bearish', response.bitcoin.usd_24h_change <= 0);

                    // Update Ethereum price
                    $('#crypto-graph-item-graph__graph-2').closest('.crypto-graph-carousel__items').find('.crypto-graph-item--price-codename .crypto-graph-item__price').text(`USD ${response.ethereum.usd.toFixed(2)}`);
                    $('#crypto-graph-item-graph__graph-2').closest('.crypto-graph-carousel__items').find('.crypto-graph-item-graph__inflution p').text(`${response.ethereum.usd_24h_change.toFixed(2)}%`).parent().toggleClass('crypto-graph-item-graph__inflution--bullish', response.ethereum.usd_24h_change > 0).toggleClass('crypto-graph-item-graph__inflution--bearish', response.ethereum.usd_24h_change <= 0);

                    // Update Tether price
                    $('#crypto-graph-item-graph__graph-3').closest('.crypto-graph-carousel__items').find('.crypto-graph-item--price-codename .crypto-graph-item__price').text(`USD ${response.tether.usd.toFixed(4)}`);
                    $('#crypto-graph-item-graph__graph-3').closest('.crypto-graph-carousel__items').find('.crypto-graph-item-graph__inflution p').text(`${response.tether.usd_24h_change.toFixed(2)}%`).parent().toggleClass('crypto-graph-item-graph__inflution--bullish', response.tether.usd_24h_change > 0).toggleClass('crypto-graph-item-graph__inflution--bearish', response.tether.usd_24h_change <= 0);

                    // Update Binance Coin price
                    $('#crypto-graph-item-graph__graph-4').closest('.crypto-graph-carousel__items').find('.crypto-graph-item--price-codename .crypto-graph-item__price').text(`USD ${response.binancecoin.usd.toFixed(2)}`);
                    $('#crypto-graph-item-graph__graph-4').closest('.crypto-graph-carousel__items').find('.crypto-graph-item-graph__inflution p').text(`${response.binancecoin.usd_24h_change.toFixed(2)}%`).parent().toggleClass('crypto-graph-item-graph__inflution--bullish', response.binancecoin.usd_24h_change > 0).toggleClass('crypto-graph-item-graph__inflution--bearish', response.binancecoin.usd_24h_change <= 0);

                    // Update Ripple price
                    $('#crypto-graph-item-graph__graph-5').closest('.crypto-graph-carousel__items').find('.crypto-graph-item--price-codename .crypto-graph-item__price').text(`USD ${response.ripple.usd.toFixed(4)}`);
                    $('#crypto-graph-item-graph__graph-5').closest('.crypto-graph-carousel__items').find('.crypto-graph-item-graph__inflution p').text(`${response.ripple.usd_24h_change.toFixed(2)}%`).parent().toggleClass('crypto-graph-item-graph__inflution--bullish', response.ripple.usd_24h_change > 0).toggleClass('crypto-graph-item-graph__inflution--bearish', response.ripple.usd_24h_change <= 0);

                    // Add this line to update the buy/sell card
                    updateBuySellCard(response);
                },
                error: err => {
                    console.error('Error fetching crypto data:', err);
                }
            });
        }

        // Fetch prices every minute
        updateCryptoPrices();
        setInterval(updateCryptoPrices, 60000);
    });

    function updateBuySellCard(response) {
        // Store current prices globally for calculations
        window.cryptoPrices = {
            btc: response.bitcoin.usd,
            eth: response.ethereum.usd,
            usdt: response.tether.usd,
            bnb: response.binancecoin.usd
        };

        // Get currently selected currency and amount
        const selectedCurrency = $('#custom-select1 .forms-group__items.selected').data('selected');
        const amount = parseFloat($('#buy-tab-pane .forms-purchase__value').first().val()) || 1;

        // Calculate total value in USD
        let priceInUSD = 0;
        switch (selectedCurrency) {
            case 'btc':
                priceInUSD = amount * response.bitcoin.usd;
                break;
            case 'eth':
                priceInUSD = amount * response.ethereum.usd;
                break;
            case 'bnb':
                priceInUSD = amount * response.binancecoin.usd;
                break;
            case 'usd':
                priceInUSD = amount;
                break;
        }

        // Update price display
        $('.buy-sell-cards__detail--prices .notes').text(`${amount} ${selectedCurrency.toUpperCase()} is roughly`);
        $('.buy-sell-cards__detail--prices .value').text(priceInUSD.toFixed(2)).append('<span class="fb-lg currency">USD</span>');
    }

    //crypto graph carousel
    $('.crypto-graph-carousel').slick({
        centerMode: true,
        slidesToShow: 1,
        slidesToScroll: 1,
        dots: true,
        infinite: true,
        cssEase: 'linear',
        variableWidth: true,
        variableHeight: true,
        dots: true,
        arrows: false,
        appendDots: $('.crypto-graph-carousel__slick-slider-dots'),
        responsive: [{
            breakpoint: 768,
            settings: {
                centerMode: true,
                centerPadding: '0px',
                arrows: false,
                dots: true,
                slidesToShow: 1
            }
        }]
    });
    $('.testimonial .testimonial-carousel').on('init afterChange', function(e, slick) {
        let currentSlick = $('.slick-current.slick-active', slick.$slideTrack);

        // get all title from carousel
        let currentTitle = currentSlick.data('slick-title');
        let prevTitle = currentSlick.prev().data('slick-title');
        let nextTitle = currentSlick.next().data('slick-title');
        let next2Title = currentSlick.nextAll().eq(1).data('slick-title');

        //get all items testimonial media text
        let currentContentCarousel = $('.testimonial-media .testimonial-media__items.active .testimonial-media__items-title');
        let prevContentCarousel = $('.testimonial-media .testimonial-media__items.prev .testimonial-media__items-title');
        let nextContentCarousel = $('.testimonial-media .testimonial-media__items.next .testimonial-media__items-title');
        let next2ContentCarousel = $('.testimonial-media .testimonial-media__items.next-2 .testimonial-media__items-title');

        //animate change media
        $('.testimonial-media .testimonial-media__items').addClass('ScaleBig');
        $('.testimonial-media .testimonial-media__items .testimonial-media__items-title').addClass('ScaleBigHideFirst');
        window.setTimeout(function() {
            $(".testimonial-media .testimonial-media__items").removeClass("ScaleBig");
            $('.testimonial-media .testimonial-media__items .testimonial-media__items-title').removeClass('ScaleBigHideFirst');
        }, 900);

        //replace title on media text with carousel order
        currentContentCarousel.text(currentTitle);
        prevContentCarousel.text(prevTitle);
        nextContentCarousel.text(nextTitle);
        next2ContentCarousel.text(next2Title);
    });

    //testimonial carousel
    $('.testimonial .testimonial-carousel').slick({
        centerMode: false,
        slidesToShow: 1,
        slidesToScroll: 1,
        dots: false,
        infinite: true,
        cssEase: 'linear',
        variableWidth: true,
        variableHeight: true,
        arrows: true,
        prevArrow: $('.testimonial-carousel__prev'),
        nextArrow: $('.testimonial-carousel__next'),
        responsive: [{
            breakpoint: 1064,
            settings: {
                centerMode: true,
                centerPadding: '0',
                slidesToShow: 1
            }
        }, {
            breakpoint: 768,
            settings: {
                centerMode: true,
                centerPadding: '0px',
                slidesToShow: 1
            }
        }]
    });

    // Add calculation logic
    $(document).ready(function() {
        // Handle input changes in buy/sell forms
        $('.forms-purchase__value').on('input', function() {
            const amount = parseFloat($(this).val()) || 0;
            const selectedCurrency = $('#custom-select1 .forms-group__items.selected').data('selected');
            if (window.cryptoPrices) {
                let priceInUSD = 0;
                switch (selectedCurrency) {
                    case 'btc':
                        priceInUSD = amount * window.cryptoPrices.btc;
                        break;
                    case 'eth':
                        priceInUSD = amount * window.cryptoPrices.eth;
                        break;
                    case 'bnb':
                        priceInUSD = amount * window.cryptoPrices.bnb;
                        break;
                    case 'usd':
                        priceInUSD = amount;
                        break;
                }
                $('.buy-sell-cards__detail--prices .notes').text(`${amount} ${selectedCurrency.toUpperCase()} is roughly`);
                $('.buy-sell-cards__detail--prices .value').text(priceInUSD.toFixed(2)).append('<span class="fb-lg currency">USD</span>');
            }
        });

        // Handle currency selection changes
        $('.forms-group__items').click(function() {
            const $dropdown = $(this).closest('.js-forms-group__dropdown');
            const $parent = $dropdown.parent();
            const selected = $(this).data('selected');

            // Update selected item
            $parent.find('.forms-group__items.selected').html($(this).html()).attr('data-selected', selected);

            // If this is the first dropdown, update the price display
            if ($parent.attr('id') === 'custom-select1' && window.cryptoPrices) {
                let priceDisplay = '';
                switch (selected) {
                    case 'btc':
                        priceDisplay = window.cryptoPrices.btc.toFixed(2);
                        break;
                    case 'eth':
                        priceDisplay = window.cryptoPrices.eth.toFixed(2);
                        break;
                    case 'bnb':
                        priceDisplay = window.cryptoPrices.bnb.toFixed(2);
                        break;
                    case 'usd':
                        priceDisplay = window.cryptoPrices.btc.toFixed(2);
                        break;
                }
                $('.buy-sell-cards__detail--prices .notes').text(`1 ${selected.toUpperCase()} is roughly`);
                $('.buy-sell-cards__detail--prices .value').text(priceDisplay).append('<span class="fb-lg currency">USD</span>');
            }

            // Trigger recalculation
            $parent.closest('.forms-purchase__box').find('.forms-purchase__value').trigger('input');
        });

        // Handle Calculate button click for staking
        $('.buy-sell-cards__forms .btn-primary').click(function() {
            if ($('#buy-tab-pane').hasClass('active')) {
                const amount = parseFloat($('#buy-tab-pane .forms-purchase__value').first().val()) || 0;
                const selectedCurrency = $('#custom-select1 .forms-group__items.selected').data('selected');

                // Fix: Get the selected days value from the text content
                const selectedDaysText = $('#custom-select2 .forms-group__items.selected .fg-items__value').text();
                const days = parseInt(selectedDaysText) || 30;

                // Calculate amount in USD
                let amountInUSD = amount;
                if (selectedCurrency !== 'usd' && window.cryptoPrices) {
                    amountInUSD = amount * window.cryptoPrices[selectedCurrency];
                }

                // Get percentage based on staking duration
                let percentage;
                switch (days) {
                    case 30:
                        percentage = 0.50; // 50% for 30 days
                        break;
                    case 60:
                        percentage = 0.70; // 70% for 60 days
                        break;
                    case 120:
                        percentage = 1.20; // 120% for 120 days
                        break;
                    default:
                        percentage = 0.50;
                }

                // Calculate total value (original amount + percentage of original amount)
                const reward = amountInUSD * percentage;
                const totalValue = amountInUSD + reward;

                // Switch to sell tab and update values
                $('#sell-tab').tab('show');

                // Update the sell tab input with total amount in original currency
                const totalInOriginalCurrency = (totalValue / window.cryptoPrices[selectedCurrency]).toFixed(6);
                $('#sell-tab-pane .forms-purchase__value').first().val(totalInOriginalCurrency);

                // Update currency selection
                $('#custom-select3 .forms-group__items.selected').html($('#custom-select1 .forms-group__items.selected').html()).attr('data-selected', selectedCurrency);

                // Update the display text
                $('#sell-tab-pane .buy-sell-cards__detail--prices .notes').text(`${amount} ${selectedCurrency.toUpperCase()} after ${days} days staking`);
                $('#sell-tab-pane .buy-sell-cards__detail--prices .value').text(totalValue.toFixed(2)).append('<span class="fb-lg currency">USD</span>');

                // Update button text
                $('#sell-tab-pane .btn-primary').text('Stake Now');

                // Debug log
                console.log(`Selected days: ${days}, Percentage: ${percentage}, Original: ${amountInUSD}, Reward: ${reward}, Total: ${totalValue}`);
            }
        });
    });
    /******/
})();
//# sourceMappingURL=landing-page-v2.js.map