// 00325167 - Number and currency format

if (typeof jQuery !== "undefined") {

    $(document).ready(function () {

        try {

            let pageObserver;

            if ($("#page_selection_seatMap").length > 0) {

                pageObserver = "#page_selection_seatMap"

            } else if ($("#page_selection_eventSeat").length > 0) {

                pageObserver = "#page_selection_eventSeat"

            } else if ($("#page_checkout_orderSummary").length > 0) {

                pageObserver = "#page_checkout_orderSummary"

            } else {

                pageObserver = ".page_container"

            }

            $(".int_part").each(function(){

                $(this).html($(this).html().replaceAll(",", "."))

                $(this).html($(this).html().replaceAll(" ", "."))

            })

            var observer = new MutationObserver(function (mutations) {

                if (document.querySelector(".amount.amount_COP") && (document.querySelector(".amount.amount_COP").innerText.includes(',') || document.querySelector(".amount.amount_COP").innerText.includes(' '))) {

                    setTimeout(function(){

                        $(".int_part").each(function(){

                            $(this).html($(this).html().replaceAll(",", "."))

                            $(this).html($(this).html().replaceAll(" ", "."))

                        })

                    }, 200)

                }

            });

            observer.observe(document.querySelector(pageObserver), {

                childList: true,

                subtree: true,

            });

        } catch (err) {

            console.log("Custom JS failed");

            console.log(err);

        }

    });

}

// 00325167 END



// 00345105

if (typeof jQuery !== "undefined") {

    $(document).ready(function () {

        var language = document.getElementsByTagName("html")[0].getAttribute("lang")

        try {

            if ($("#page_selection_seatMap").length > 0) {

                var observer = new MutationObserver(function (mutations) {

                    if ($(".stx-text-caption1").length > 0 && $(".stx-text-caption2").length > 0) {

                        setTimeout(function () {

                            $(".stx-sm-sidebar-scroll-content .stx-text-caption1").each(function () {

                                if($(this).html().includes(",")){

                                    language == 'es' ? $(this).html($(this).html().replace(',00','').replaceAll(",", ".")) : $(this).html($(this).html().replace('.00','').replaceAll(",", "."));

                                }

                            });

                            $(".stx-sm-seat-selection-cart .stx-text-caption2 div").each(function () {

                                if($(this).html().includes(",")){

                                    language == 'es' ? $(this).html($(this).html().replace(',00','').replaceAll(",", ".")) : $(this).html($(this).html().replace('.00','').replaceAll(",", "."));

                                }

                            });

                            // replace currency code + amount for dropdown

                            $(".stx-sm-nnarea-detail-tariff-dropdown .stx-sm-nnarea-detail-amount").each(function () {

                                if($(this).html().includes("COP")){

                                    if($('#cs_amount').length ==0){

                                        let cs_amount = '<span id="cs_amount">'+$(this).text().replace(/\s/g, '').replace('COP', "$").replace('.00','').replace(/\B(?=(\d{3})+(?!\d))/g, ".")+'</span>';

                                        $(this).hide();

                                        $(cs_amount).insertAfter($(this));

                                    }

                                }

                            });

                            // update total price

                            $(".stx-sm-seat-selection-cart .stx-text-caption1 span").each(function () {

                                if($(this).html().includes("$")){

                                    if($('#cs_total').length ==0){

                                        let total = language == 'es' ? '<div id="cs_total">'+$(this).text().replace(',00','')+'</div>' : '<div id="cs_total">'+$(this).text().replace('.00','')+'</div>';

                                        $(this).hide();

                                        $(total).insertAfter($(this));

                                    }

                                    if ($('#cs_total').length >0 && $('#cs_total').text() != $(this).text()) {

                                        formatTotal($('#cs_total'),$(this));

                                    }

                                }

                            });

                        }, 200);

                    }

                });

                observer.observe(document.querySelector("#rootSeatmapWidget"), {

                    childList: true,

                    subtree: true,

                });

                function formatTotal(el1,el2){

                    language == 'es' ? el1.html(el2.text().replace(',00','').replaceAll(",", ".")) : el1.html(el2.text().replace('.00','').replaceAll(",", "."));

                    observer.disconnect();

                    observer.observe(document.querySelector("#rootSeatmapWidget"), {

                        childList: true,

                        subtree: true,

                    });



                }

            }



            // WA for resale input

            let scriptTag = $("#resell_tickets_form").next("script")[0];

            let scriptContent = "";

            if (scriptTag) {

                scriptContent = scriptTag.textContent || scriptTag.innerText || "";

            }



            // Prepend your custom code

            let newContent =

              `

            amountDecimalSeaparator = ',';

            priceSeparator = '.';

            // your extra logic here

            ` + scriptContent;



            // Execute without replacing the tag

            if (scriptContent) {

                eval(newContent);

            }



            let removeDecimalPart = function ($input) {

              let v = $input.val();

              $input.val(v.substring(0, v.length - 3));

            };



            $('input[id^="resale_price_input_"]').each((i1, r1) => {

              let $input = $(r1)[0];



              // Manually

              removeDecimalPart($(r1));



              // Save original

              const originalBlur = $input.onblur;



              // Override

              $input.onblur = function (event) {

                $('input[id^="resale_price_input_"]').each((i2, r2) => {

                  removeDecimalPart($(r2));

                });

                if (originalBlur) {

                  return originalBlur.call(this, event); // call original

                }

              };

            });

        } catch (err) {

            console.log("Custom JS failed");

            console.log(err);

        }

    });

}

// 00345105 END

