var Wick = Wick || {};
Wick.YourDetails = (function () {

    let reasonSelect = $("#reason"),
      wickesInstalled = $(".wickes-installed"),
      kitchenBlock = $(".kitchen-bathroom"),
      otherEnquiryBlock = $(".other-enquiries"),
      storeEnquiryBlock = $(".store-enquiry"),
      helpRadioBlock = $('.your-details__help-wrap input'),
      existingOrder = $(".ex-order"),
      bookDeliveryDate = $(".book-delivery-date"),
      guaranteeClaim = $(".guarantee-claim"),
      workmanshipGuaranteeClaim = $(".workmanship-guarantee-claim"),
      existingOrderKitchen = $(".ex-order-kitchen"),
      bookDeliveryDateKitchen = $(".book-delivery-date-kitchen"),
      guaranteeClaimKitchen = $(".guarantee-claim-kitchen"),
      contactChoise = $(".your-details__add"),
      placeingOrder = $(".placing-order-on"),
      cancellingOrderOn = $(".cancelling-order-on"),
      availabilityInfo = $(".availability-info-on"),
      onlineOrder = $(".order-deliv-online"),
      quaranteeClaim = $(".product-guarantee-claim"),
      enquiryNotRelatedToOrder = $(".enquiry-not-related-to-order"),
      complaintRaise = $(".complaint-raise"),
      unresolvedComplaint = $(".unresolved-complaint"),
      attachmentsFile = $(".your-details__attachments-file"),
      notificationForAttachments = $(".your-details__attachments-notification"),
      titleField = $(".title-field"),
      isVisible = "d-block",
      isHidden = "d-none",
      $linkTo = $('.follow-link'),
      $dest = $('.your-details__wrap'),
      $warning = $('.notification_warning');

    reasonSelect.on('change', function() {
        switch ($('#reason :selected').attr('data-val')) {
            case 'wickes-installed':
                wickesInstalled.addClass(isVisible);
                kitchenBlock.removeClass(isVisible);
                otherEnquiryBlock.removeClass(isVisible);
                storeEnquiryBlock.removeClass(isVisible);
                break;
            case 'kitchen-bathroom':
                kitchenBlock.addClass(isVisible);
                wickesInstalled.removeClass(isVisible);
                otherEnquiryBlock.removeClass(isVisible);
                storeEnquiryBlock.removeClass(isVisible);
                break;
            case 'other-enquiries':
                otherEnquiryBlock.addClass(isVisible);
                wickesInstalled.removeClass(isVisible);
                kitchenBlock.removeClass(isVisible);
                storeEnquiryBlock.removeClass(isVisible);
                break;
            case 'store-enquiry':
                storeEnquiryBlock.addClass(isVisible);
                wickesInstalled.removeClass(isVisible);
                kitchenBlock.removeClass(isVisible);
                otherEnquiryBlock.removeClass(isVisible);
                break;
        }

        if ($('#reason :selected').attr('data-val') === 'wickes-installed' || $('#reason :selected').attr('data-val') === 'kitchen-bathroom') {
            titleField.addClass(isHidden);
            contactChoise.addClass(isHidden);
        }
        else if ($('#reason :selected').attr('data-val') === 'other-enquiries') {
            titleField.removeClass(isHidden);
            contactChoise.removeClass(isHidden);
            contactChoise.find('.form-row__label').addClass('form-row__label_required');
        }
    });

    $(helpRadioBlock).change(function () {
        switch ($(this).attr("id")) {
            case '0_ex-order_':
                existingOrder.addClass(isVisible);
                bookDeliveryDate.removeClass(isVisible);
                guaranteeClaim.removeClass(isVisible);
                workmanshipGuaranteeClaim.removeClass(isVisible);
                attachmentsFile.addClass(isHidden);
                notificationForAttachments.addClass(isHidden);
                break;
            case '0_placing-order-on_':
            case '2_availability-info-on_':
            case '5_enquiry-not-related-to-order_':
            case '6_complaint-raise_':
            case '7_unresolved-complaint_':
                $warning.removeClass(isVisible);
                quaranteeClaim.removeClass(isVisible);
                enquiryNotRelatedToOrder.removeClass(isVisible);
                cancellingOrderOn.removeClass(isVisible);
                placeingOrder.removeClass(isVisible);
                availabilityInfo.removeClass(isVisible);
                onlineOrder.removeClass(isVisible);
                complaintRaise.removeClass(isVisible);
                unresolvedComplaint.removeClass(isVisible);
                attachmentsFile.addClass(isHidden);
                notificationForAttachments.addClass(isHidden);
                break;
            case '1_cancelling-order-on_':
                $warning.removeClass(isVisible);
                quaranteeClaim.removeClass(isVisible);
                enquiryNotRelatedToOrder.removeClass(isVisible);
                cancellingOrderOn.addClass(isVisible);
                placeingOrder.removeClass(isVisible);
                availabilityInfo.removeClass(isVisible);
                onlineOrder.removeClass(isVisible);
                complaintRaise.removeClass(isVisible);
                unresolvedComplaint.removeClass(isVisible);
                attachmentsFile.addClass(isHidden);
                notificationForAttachments.addClass(isHidden);
                break;
            case '3_online-order-on_':
                $warning.addClass(isVisible);
                quaranteeClaim.removeClass(isVisible);
                enquiryNotRelatedToOrder.removeClass(isVisible);
                onlineOrder.addClass(isVisible);
                placeingOrder.removeClass(isVisible);
                cancellingOrderOn.removeClass(isVisible);
                availabilityInfo.removeClass(isVisible);
                complaintRaise.removeClass(isVisible);
                unresolvedComplaint.removeClass(isVisible);
                attachmentsFile.addClass(isHidden);
                notificationForAttachments.addClass(isHidden);
                break;
            case '4_product-guarantee-claim_':
                $warning.removeClass(isVisible);
                quaranteeClaim.addClass(isVisible);
                enquiryNotRelatedToOrder.removeClass(isVisible);
                onlineOrder.removeClass(isVisible);
                placeingOrder.removeClass(isVisible);
                cancellingOrderOn.removeClass(isVisible);
                availabilityInfo.removeClass(isVisible);
                complaintRaise.removeClass(isVisible);
                unresolvedComplaint.removeClass(isVisible);
                attachmentsFile.removeClass(isHidden);
                notificationForAttachments.removeClass(isHidden);
                break;
            case '1_book-delivery-date_':
                existingOrder.removeClass(isVisible);
                bookDeliveryDate.addClass(isVisible);
                guaranteeClaim.removeClass(isVisible);
                workmanshipGuaranteeClaim.removeClass(isVisible);
                attachmentsFile.addClass(isHidden);
                notificationForAttachments.addClass(isHidden);
                break;
            case '2_guarantee-claim_':
                existingOrder.removeClass(isVisible);
                bookDeliveryDate.removeClass(isVisible);
                guaranteeClaim.addClass(isVisible);
                workmanshipGuaranteeClaim.removeClass(isVisible);
                attachmentsFile.removeClass(isHidden);
                notificationForAttachments.removeClass(isHidden);
                break;
            case '3_workmanship-guarantee-claim_':
                existingOrder.removeClass(isVisible);
                bookDeliveryDate.removeClass(isVisible);
                guaranteeClaim.removeClass(isVisible);
                workmanshipGuaranteeClaim.addClass(isVisible);
                attachmentsFile.addClass(isHidden);
                notificationForAttachments.addClass(isHidden);
                break;
            case '4_unresolved-complaint_':
                existingOrder.removeClass(isVisible);
                bookDeliveryDate.removeClass(isVisible);
                guaranteeClaim.removeClass(isVisible);
                workmanshipGuaranteeClaim.removeClass(isVisible);
                attachmentsFile.addClass(isHidden);
                notificationForAttachments.addClass(isHidden);
                break;
            case '0_ex-order-kitchen_':
                existingOrderKitchen.addClass(isVisible);
                bookDeliveryDateKitchen.removeClass(isVisible);
                guaranteeClaimKitchen.removeClass(isVisible);
                attachmentsFile.addClass(isHidden);
                notificationForAttachments.addClass(isHidden);
                break;
            case '1_book-delivery-date-kitchen_':
                existingOrderKitchen.removeClass(isVisible);
                bookDeliveryDateKitchen.addClass(isVisible);
                guaranteeClaimKitchen.removeClass(isVisible);
                attachmentsFile.addClass(isHidden);
                notificationForAttachments.addClass(isHidden);
                break;
            case '2_guarantee-claim-kitchen_':
                existingOrderKitchen.removeClass(isVisible);
                bookDeliveryDateKitchen.removeClass(isVisible);
                guaranteeClaimKitchen.addClass(isVisible);
                attachmentsFile.removeClass(isHidden);
                notificationForAttachments.removeClass(isHidden);
                break;
            case '3_unresolved-complaint-kitchen_':
                existingOrderKitchen.removeClass(isVisible);
                bookDeliveryDateKitchen.removeClass(isVisible);
                guaranteeClaimKitchen.removeClass(isVisible);
                attachmentsFile.addClass(isHidden);
                notificationForAttachments.addClass(isHidden);
                break;
        }

    });

    $(function(){
        $linkTo.on('click', function(event) {
            event.preventDefault();
            let dn = $dest.offset().top - 10;
            $('html, body').animate({scrollTop: dn}, 1000);
        });
    });

})();
