let activateParcelLocker = setInterval(function() {
    let shippingMethodSelector = $('input[name="shipping_method"]:checked');
    if (shippingMethodSelector.length !== 0) {
        if (shippingMethodSelector.attr('value').indexOf('inpost_shipping_') !== -1) {
            shippingMethodSelector.parent().parent().find('.parcel-locker').removeClass('hidden');
            clearInterval(activateParcelLocker);
        }
    }
}, 200);

$(document).on('change', 'input[name="shipping_method"]', function(e) {
    $('.parcel-locker, .parcel-locker-selection-data').each(function(){
        $(this).addClass('hidden');
    });

    $(this).parent().parent().find('.parcel-locker').removeClass('hidden');
});

$(document).on('click', '#btn-parcel-locker', function() {
    $('#inpostGeoWidgetModal').modal('show');
});

function afterPointSelected(point) {
    $('[name="parcelLocker"]').each(function() {
        $(this).val('');
    });

    let shippingMethodSelector = $('input[name="shipping_method"]:checked');
    shippingMethodSelector.parent().parent().find('.parcel-locker-value').val(point.name);
    shippingMethodSelector.parent().parent().find('.parcel-locker-selection-data').html(point.name + '<br/>' + point.address.line1 + '<br/>' + point.address.line2);
    shippingMethodSelector.parent().parent().find('.parcel-locker-selection-data').removeClass('hidden');

    $('#inpostGeoWidgetModal').modal('hide');
}