<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">'use strict';

new Vue({
    el: '#vue',
    data: {
        agency,
        lodging_id,
        arrival,
        departure,
        people,
        isSearch,
        available,
        release,
        release_hours,
        latitude,
        longitude,
        langInt,
        langStr,
        selectedRate: '',
        currentRate: {},
        propertyRates: [],
        isHotel: false,
        isBookable: false,
        preloading: true,
    },
    filters: {
        roundNumber: (value) =&gt; {
            return value ? Math.ceil(value) : '';
        }
    },
    created() {
        this.getProperty();

        // Si hi ha querys a la URL, vol dir que venim d'una cerca
        if (isSearch) {
            this.getRateData();
        }
    },
    watch: {
        selectedRate(newQ, oldQ) {
            this.toggleRate(newQ);
        }
    },
    methods: {
        getProperty() {
            $.postJSON("/WebService.asmx/Lodging", JSON.stringify({
                id: this.lodging_id,
                language: 'en'
            }), (json) =&gt; {
                let type = JSON.parse(json.d).Lodging.lodging_type;
                if (type === 'Hotel' || type === 'Resort' || type === 'Parador' || type === 'Spa' || type === 'Shrine' || type === 'Rural hotel' || type === 'Castle' || type === 'Hostel' || type === 'Rural guesthouse' || type === 'Boarding house' || type === 'Youth hostel' || type === 'Rural retreat' || type === 'Bed and breakfast' || type === 'Guesthouse' || type === 'Camping') {
                    this.isHotel = true;
                }
            });
        },
        getRateData() {

            const nights = dateDiff(arrival, departure);
            if (this.agency &gt; 0) {
                $.postJSON("/WebService.asmx/DailyAgencyRates", JSON.stringify({
                    id: this.lodging_id,
                    arrival: this.arrival,
                    departure: this.departure,
                    people: this.people,
                    language: this.langStr
                }), (json) =&gt; {
                    try {
                        this.propertyRates = JSON.parse(json.d).DailyAgencyRates.map(rate =&gt; {
                            rate.closed_to_arrival = rate.closed_to_arrival == 'true';
                            rate.closed_to_departure = rate.closed_to_departure == 'true';

                            if (rate.closed_to_arrival) {
                                rate.arrival_day = getDayName(this.arrival);
                            }
                            if (rate.closed_to_departure) {
                                rate.departure_day = getDayName(this.departure);
                            }
                            if (rate.arrival_weekday &gt; 0) {
                                rate.check_day = setmana[rate.arrival_weekday];
                            }
                            rate.minimum_check = rate.minimum_stay &lt;= nights;
                            rate.url = `/${this.langStr}/31/book-now/?h=${this.lodging_id}&amp;arrival=${this.arrival}&amp;departure=${this.departure}&amp;guests=${this.people}`;

                            if (!this.isHotel) {
                                rate.url += '&amp;rate=' + rate.rate_id;
                            }

                            //rate.price -= rate.cleaning_fee
                            //rate.price = (parseFloat(rate.price) + Math.floor(rate.price * rate.comission) / 100 + parseFloat(rate.cleaning_fee)).toFixed(2)


                            return rate;
                        });

                        this.currentRate = this.propertyRates[rateIndex];

                        if (this.currentRate) {
                            this.isBookable = !this.currentRate.closed_to_arrival &amp;&amp; !this.currentRate.closed_to_departure &amp;&amp; this.currentRate.minimum_check &amp;&amp; this.releaseChecker(this.arrival);

                            if (!this.selectedRate) {
                                this.selectedRate = this.currentRate.rate_id;
                            }
                        }

                        this.isLoadSetter();

                    } catch (e) {
                        console.error(e);
                    }
                });
            } else if (nights /*&lt; 28*/) {
                $.postJSON("/WebService.asmx/DailyRates", JSON.stringify({
                    id: this.lodging_id,
                    arrival: this.arrival,
                    departure: this.departure,
                    people: this.people,
                    language: this.langStr
                }), (json) =&gt; {
                    try {
                        this.propertyRates = JSON.parse(json.d).DailyRates;

                        this.currentRate = this.propertyRates[0];
                        this.currentRate.no_dispo = false;
                        this.currentRate.closed_to_arrival = this.currentRate.closed_to_arrival === 'true' || this.currentRate.closed_to_arrival === true;
                        this.currentRate.closed_to_departure = this.currentRate.closed_to_departure === 'true' || this.currentRate.closed_to_departure === true;

                        if (this.currentRate.closed_to_arrival) {
                            this.currentRate.arrival_day = getDayName(this.arrival);
                        }
                        if (this.currentRate.closed_to_departure) {
                            this.currentRate.departure_day = getDayName(this.departure);
                        }
                        if (this.currentRate.arrival_weekday &gt; 0) {
                            this.currentRate.arrival_weekday == 7 ? this.currentRate.check_day = setmana[0] : this.currentRate.check_day = setmana[this.currentRate.arrival_weekday];
                        }
                        this.currentRate.minimum_check = this.currentRate.minimum_stay &lt;= nights;

                        this.isBookable = !this.currentRate.closed_to_arrival &amp;&amp; !this.currentRate.closed_to_departure &amp;&amp; this.currentRate.minimum_check &amp;&amp; this.releaseChecker(this.arrival);

                        this.currentRate.url = '/' + this.langStr + '/31/' + cleanText(traductor.reserva) + '?h=' + this.lodging_id + '&amp;arrival=' + this.arrival + '&amp;departure=' + this.departure + '&amp;guests=' + this.getPeople();
                        if (!this.isHotel) {
                            this.currentRate.url += '&amp;rate=' + this.currentRate.rate_id;
                        }

                        if (!this.selectedRate) {
                            this.selectedRate = this.propertyRates[0].rate_id;
                        }

                        this.isLoadSetter();

                    } catch (e) {
                        console.error(e);
                    }
                });
            } else {
                $.postJSON("/WebService.asmx/MonthlyRate", JSON.stringify({
                    id: this.lodging_id,
                    arrival: this.arrival,
                    departure: this.departure,
                }), (json) =&gt; {
                    try {
                        this.currentRate = JSON.parse(json.d).MonthlyRate;
                        this.currentRate.no_dispo = false;
                        this.isBookable = true;
                        this.currentRate.price = Math.ceil(parseInt(this.currentRate.price) + parseInt(this.currentRate.cleaning));
                        this.currentRate.url = '/' + this.langStr + '/32/' + cleanText(traductor.reserva) + '?h=' + this.lodging_id + '&amp;arrival=' + this.arrival + '&amp;departure=' + this.departure + '&amp;guests=' + this.getPeople();

                        this.currentRate.minimum_check = this.currentRate.minimum_stay &lt;= nights;
                        this.currentRate.monthly = true;
                        this.isLoadSetter();

                    } catch (e) {
                        console.error(e);
                    }
                });
            }
        },
        getArrivalDate() {
            return document.querySelector('#dEntrada').value;
        },
        getDepartureDate() {
            return document.querySelector('#dSortida').value;
        },
        getPeople() {
            return document.querySelector('#nPersones option:checked').value;
        },
        toggleRate(id) {
            // aquesta era la Ãºnica lÃ­nia que hi havia abans, aixÃ² era mÃ©s maco...
            this.currentRate = this.propertyRates.filter(d =&gt; d.rate_id === id)[0];
            // aixÃ² segur que es pot optimitzar perquÃ¨ Ã©s repeticiÃ³...
            let arrivalDate = this.getArrivalDate();
            let departureDate = this.getDepartureDate();
            let nights = dateDiff(arrivalDate, departureDate);

            this.currentRate.closed_to_arrival = this.currentRate.closed_to_arrival === 'true' || this.currentRate.closed_to_arrival === true;
            this.currentRate.closed_to_departure = this.currentRate.closed_to_departure === 'true' || this.currentRate.closed_to_departure === true;

            if (this.currentRate.closed_to_arrival) {
                this.currentRate.arrival_day = getDayName(arrivalDate);
            }
            if (this.currentRate.closed_to_departure) {
                this.currentRate.departure_day = getDayName(departureDate);
            }
            if (this.currentRate.arrival_weekday &gt; 0) {
                this.currentRate.arrival_weekday == 7 ? this.currentRate.check_day = setmana[0] : this.currentRate.check_day = setmana[this.currentRate.arrival_weekday];
            }
            this.currentRate.minimum_check = this.currentRate.minimum_stay &lt;= nights;

            this.isBookable = !this.currentRate.closed_to_arrival &amp;&amp; !this.currentRate.closed_to_departure &amp;&amp; this.currentRate.minimum_check &amp;&amp; this.releaseChecker(arrivalDate);

            this.currentRate.url = '/' + this.langStr + '/31/' + cleanText(traductor.reserva) + '?h=' + this.lodging_id + '&amp;arrival=' + arrivalDate + '&amp;departure=' + departureDate + '&amp;guests=' + this.getPeople();
            if (!this.isHotel) {
                this.currentRate.url += '&amp;rate=' + this.currentRate.rate_id;
            }
        },
        releaseChecker(arrivalDate) {
            const dateRelease = new Date().addDays(parseInt(this.release)).toLocaleDateString('es-ES');
            const releaseDays = dateDiff(dateRelease, arrivalDate);

            if (releaseDays &lt; 0) {
                this.available = false;
            }

            if (releaseDays == 0 &amp;&amp; parseInt(this.release) == 0 &amp;&amp; parseInt(this.release_hours) &gt; 0) {
                const currentUHTChour = new Date().getUTCHours();
                const spainGMTdiff = 2;
                const maxHourArrival = 24 - this.release_hours;

                if (currentUHTChour + spainGMTdiff &gt;= maxHourArrival) {
                    this.available = false;
                }
            }
            return this.available;
        },
        isLoadSetter() {
            setTimeout(() =&gt; {
                this.preloading = !this.preloading;
            }, 500);
        }
    }
});</pre></body></html>