class Product {

    constructor() {
    }

    /* Products Images Slider & Thumbs Init */
    initProductSlider() {
        try {
            var productDetailsThumbsSlider = new Swiper(".product-details-thumbs-slider", {
                spaceBetween: 20,
                slidesPerView: 5,
                watchSlidesProgress: true,
                direction: 'horizontal',
                breakpoints: {
                    1024: {
                        direction: 'vertical',
                        slidesPerView: 4,
                        spaceBetween: 20
                    }
                },
                navigation: {
                    nextEl: ".swiper-button-next",
                    prevEl: ".swiper-button-prev",
                },
                rewind: true
    
            })
            var productDetailsSlider = new Swiper(".product-details-slider", {
                spaceBetween: 10,
                pagination: {
                    el: `.product-details-slider-pagination`,
                    clickable: true,
                },
                navigation: {
                    clickable: true,
                    nextEl: `.product-details-slider-next`,
                    prevEl: `.product-details-slider-prev`,
                },
                thumbs: {
                    swiper: productDetailsThumbsSlider,
                },
                rewind: true
            })
            
        } catch (error) {
            console.log(error);
        }
        

    }
    /* Notify Availability Method */
    sendProductNotifyMe() {
        var productId = document.querySelector('.send-notify-product-id').value;
        var email = document.querySelector('.send-notify-email').value;

        zid.store.product.setAvailabilityNotificationEmail(productId, email).then(function (response) {
            if (response.status === 'success') {
                toastr.success('Sent successfully', null);
            } else {
                toastr.error('Notify me failed', 'Sorry');
            }
        });
    }
    /* Set Review Stars Count */
    setReviewStarsCount() {
        // Get all elements with the class 'review-star-selector'
        var elements = document.querySelectorAll('.review-star-selector');

        // Loop through each element and add a click event listener
        elements.forEach((element, i) => {
            element.addEventListener('click', (event) => {
                // Reset Counting Styles
                elements.forEach((element) => {
                    element.classList.remove('text-yellow-400')
                })
                // Style Selected Stars Count
                element.classList.add('text-yellow-400');
                for (let j = 0; j < i; j++) {
                    elements[j].classList.add('text-yellow-400')
                }
                // Set Selected Stars Count
                document.getElementById('stars-count-value').value = i + 1;
                console.log('Stars Count Value: ', i + 1);
            });
        });
    }
    /* Submit Review */
    submitReview(productId) {
        // Get Form Data 
        var isReviewCustomerAnonymous = document.getElementById('is_review_customer_anonymous').checked;
        var reviewCount = document.getElementById('stars-count-value').value;
        var reviewMessage = document.getElementById('review-comment').value;

        // Submit Review
        zid.store.product.addReview(productId, reviewMessage, reviewCount, isReviewCustomerAnonymous).then((response) => {
            if (response.status === 'success') {
                toastr.success("شكرًا لتقييمك، سيتم مراجعة التقييم ونشره على المتجر", "تم الإرسال بنجاح");
            } else {
                toastr.error(response.data.message, 'عفوا ');
            }
        });
    }
    /* DOM Qty Changes Handler (Deprecated) */
    // updateQtyInput(method, productId) {
    //     console.log("Method", method, " was fired!");
    //     // Get Current Quanity Input Value
    //     var currentQtyInputValue = document.getElementById(`qty-input-${productId}`);
    //     // Update Quantity Input Value
    //     if (method == 'inc') {
    //         // Increase
    //         currentQtyInputValue.value = Number(currentQtyInputValue.value) + 1;
    //         // this.updateProductQuantity((Number(currentQtyInputValue.value)))
    //     } else {
    //         // Decrease
    //         if ((Number(currentQtyInputValue.value)) > 1) {
    //             currentQtyInputValue.value = Number(currentQtyInputValue.value) - 1;
    //             // this.updateProductQuantity((Number(currentQtyInputValue.value)))
    //         }
    //     }

    // }
    /* Update Product Total Summary (Deprecated) */
    // updateProductQuantity(qty) {
    //     if (qty >= 1) {
    //         // Get Current Quanity Input Element
    //         var currentQtyInputValue = document.getElementById(`qty-input-${this.product.id}`);
    //         // Get base price value 
    //         var basePrice = currentQtyInputValue.getAttribute("data-base-price");
    //         // Get Currency Symbol
    //         var currencySymbol = currentQtyInputValue.getAttribute("data-currency-symbol");
    //         // Update Product Quantity
    //         var updatedPrice = qty * basePrice;
    //         console.log("Updated Price: ", updatedPrice.toFixed(2), currencySymbol);
    //         document.getElementById('product-price-summary').innerText = `${updatedPrice.toFixed(2)} ${currencySymbol}`
    //     }

    // }
    /* Listen to changes (Deprecated) */
    // watchElements() {
    //     /* Watch Quanity Input Changes */
    //     var quantityInput = document.getElementById(`qty-input-${this.product.id}`);
    //     // Update Total Summary Value
    //     quantityInput.addEventListener("change", (event) => {
    //         if (event.target.value < 1 ) {
    //             event.target.value = 1
    //         }
    //         // this.updateProductQuantity((Number(event.target.value)))
    //     })

    //     /* Watch Options Changes (Deprecated) */
    //     // var optionsElements = document.querySelectorAll('.product-option');
    //     // optionsElements.forEach((element) => {
    //     //     element.addEventListener('click', (event) => {
    //     //         for (let i = 0; i < this.product.variants.length; i++) {
    //     //             if (this.product.variants[i].id == element.id) {
    //     //                 /* Set Selected Product */
    //     //                 quantityInput.setAttribute("data-selected-product-id", element.id);
    //     //                 /* Update Base Price */
    //     //                 quantityInput.setAttribute("data-base-price", this.product.variants[i].sale_price);
    //     //                 /* Update Total Summary Value */
    //     //                 // this.updateProductQuantity((Number(quantityInput.value)))
    //     //             }
    //     //         }
    //     //     })
    //     // })
    // }
    /* Description Read More Method (Deprecated) */
    // initReadMore() {
    //     document.querySelector('#btn-show-more').addEventListener('click', function (e) {
    //         var moreContentDivs = document.querySelectorAll('#more-content');
    //         moreContentDivs.forEach(function (div) {
    //             e.target.classList.add('is-expanded');
    //             div.style.maxHeight = div.scrollHeight + 'px';
    //         });
    //         e.target.remove();
    //     });
    // }
    
}