class InfoClientTrip {

    static showArrivalClient(trip) {
        const config = Session.get("configGeneral");
        const picturesLink = config.find(item => {
            return item.key === 'link_storage_pictures';
        });

        const profileImage = trip.customer.profileImage
        const finalLink = `${picturesLink.value}customer/profile/compressed/${profileImage}`;

        const elementProperty = new ElementProperty();
        elementProperty.getElement(".modal-signaling-arrival", element => element.classList.add("active"));

        elementProperty.getElement(".name-client-trip", element => {
            element.innerHTML = trip.customer.nickname;
        });
        elementProperty.getElement(".image-profile-driver", element => {
            if (trip.customer.profileImage === null) {
                element.src = 'webfiles/img/icon/default.jpg';
                return;
            }
            // element.src = CLIENT_PROFILE + trip.customer.profileImage;
            element.src = finalLink;
        });
        elementProperty.addEventInElement(".phone-driver", "onclick", function () {
            location.href = "tel:" + trip.customer.phone;
        });
        elementProperty.addEventInElement(".chat-driver", "onclick", function () {
            Route.redirectDynamic("Driver", "Chat");
            InfoClientTrip.closeArrivalClient();
        });
        elementProperty.addEventInElement(".close-modal-arrival", "onclick", function () {
            InfoClientTrip.closeArrivalClient();
        });
    }

    static closeArrivalClient() {
        const elementProperty = new ElementProperty();
        elementProperty.getElement(".modal-signaling-arrival", element => element.classList.remove("active"));
    }

    static showDataClientTrip(trip) {
        const elementProperty = new ElementProperty();
        elementProperty.getElement(".modal-data-client", element => element.classList.add("active"));

        elementProperty.getElement(".name-client-trip", element => {
            element.innerHTML = trip.customer.nickname;
        });
        elementProperty.getElement(".origin-client", element => {
            element.innerHTML = trip.origin.address;
        });
        elementProperty.getElement(".destination-client", element => {
            if (trip.tripCallTypeId === TRIP_CALL_TAXIMETER) {
                element.style.display = "none";
            } else {
                element.style = "";
            }
            element.innerHTML = trip.destination.name;
        });
        elementProperty.getElement(".image-profile-driver", element => {
            const config = Session.get("configGeneral");
            const picturesLink = config.find(item => {
                return item.key === 'link_storage_pictures';
            });

            const profileImage = trip.customer.profileImage
            const finalLink = `${picturesLink.value}customer/profile/compressed/${profileImage}`;

            if (trip.customer.profileImage === null) {
                element.src = 'webfiles/img/icon/default.jpg';
                return;
            }
            // element.src = CLIENT_PROFILE + trip.customer.profileImage;
            element.src = finalLink;
        });
        elementProperty.addEventInElement(".image-profile-driver", "onerror", function () {
            this.src = 'webfiles/img/icon/default.jpg';
        });
        elementProperty.getElement(".price-trip", element => {
            const configCity = Session.get("cityConfig");

            const showPriceField = configCity.enabledDriverFields.accept.price;
            if (showPriceField) {
                element.style.display = "block";
            } else {
                element.style.display = "none";
            }

            if (showPriceField) {
                if (trip.tripCallTypeId === TRIP_CALL_TAXIMETER) {
                    element.style.display = "none";
                } else {
                    element.style = "";
                }
            }

            element.innerHTML = `<span>${CityConfig.getTypeCoin()}</span>${Mask.maskMoney(parseFloat(trip.price))}`;
        });

        elementProperty.addEventInElement(".close-data-client", "onclick", function () {
            InfoClientTrip.closeDataClient();
        });
        elementProperty.getElement(".payment-data-client", element => {
            const configCity = Session.get("cityConfig");

            if (configCity.showFormOfPaymentToDriverDuringTrip != null)
                if (configCity.showFormOfPaymentToDriverDuringTrip == true) {
                    element.style.display = "block";
                } else {
                    element.style.display = "none";
                }

            element.innerHTML = `${getTextTranslate("trip","text-payment-in")}${trip.tripPaymentForm}`
        })
    }


    static showDataClientTripWait(trip) {
        const elementProperty = new ElementProperty();
        elementProperty.addClass(".modal-data-client-trip-wait", "active");

        elementProperty.getElement(".name-client-trip", element => {
            element.innerHTML = trip.customer.nickname;
        });
        elementProperty.getElement(".origin-client", element => {
            element.innerHTML = trip.origin.address;
        });
        elementProperty.getElement(".destination-client", element => {
            if (trip.tripCallTypeId === TRIP_CALL_TAXIMETER) {
                element.style.display = "none";
            } else {
                element.style = "";
            }
            element.innerHTML = trip.destination.name;
        });
        elementProperty.getElement(".image-profile-driver", element => {
            const config = Session.get("configGeneral");
            const picturesLink = config.find(item => {
                return item.key === 'link_storage_pictures';
            });

            const profileImage = trip.customer.profileImage
            const finalLink = `${picturesLink.value}customer/profile/compressed/${profileImage}`;

            if (trip.customer.profileImage === null) {
                element.src = 'webfiles/img/icon/default.jpg';
                return;
            }
            // element.src = CLIENT_PROFILE + trip.customer.profileImage;
            element.src = finalLink;
        });
        elementProperty.addEventInElement(".image-profile-driver", "onerror", function () {
            this.src = 'webfiles/img/icon/default.jpg';
        });
        elementProperty.getElement(".price-trip", element => {
            const configCity = Session.get("cityConfig");

            if (configCity.showPriceWhileTrip != null)
                if (configCity.showPriceWhileTrip == true) {
                    element.style.display = "block";
                } else {
                    element.style.display = "none";
                }

            if (trip.tripCallTypeId === TRIP_CALL_TAXIMETER) {
                element.style.display = "none";
            } else {
                element.style = "";
            }
            element.innerHTML = `<span>${CityConfig.getTypeCoin()}</span>${Mask.maskMoney(parseFloat(trip.price))}`;
        });

        elementProperty.addEventInElement(".close-data-client-wait", "onclick", function () {
            elementProperty.removeClass(".modal-data-client-trip-wait", "active");
        });
        elementProperty.getElement(".payment-data-client", element => {
            const configCity = Session.get("cityConfig");

            if (configCity.showFormOfPaymentToDriverDuringTrip != null)
                if (configCity.showFormOfPaymentToDriverDuringTrip == true) {
                    element.style.display = "block";
                } else {
                    element.style.display = "none";
                }

            element.innerHTML = `${getTextTranslate("trip","text-payment-in")}${trip.tripPaymentForm}`
        })
    }

    static closeDataClient() {
        const elementProperty = new ElementProperty();

        elementProperty.removeClass(".modal-data-client", "active");
    }
}
