jQuery(document).ready(function($) {
    // $('input[name="quantity"]').val('10');
    const defw = 3.631;

    $('.bwdpbwc-option').click(function(e) {
        e.preventDefault();
        $('.bwdpbwc-option').removeClass('selected');
        $(this).addClass('selected');
        let qty = $(this).data('qty') ;
        let price = $(this).data('price');
        let newPrice = price/qty;
        let currency = $('p.price .woocommerce-Price-amount bdi').find('span.woocommerce-Price-currencySymbol');
        // console.log(typeof qty);
        // console.log(typeof $( 'input[name=quantity]' ).prop( 'step', 1).val());

        // $('form.cart').find('input[name=quantity]').attr('max', 100);
// console.log(currency);
        $('form.cart').find('input[name=quantity]').prop('step', 1).val(qty);
        $('p.price .woocommerce-Price-amount bdi').html('<span class="woocommerce-Price-currencySymbol">'+currency.html()+'</span>' + newPrice);


        let qtyWidth = (qty.toString().length/1.5) + defw;
        $('form.cart').find('input[name=quantity]').css('width', qtyWidth + 'em');


        // console.log($('input[name="quantity"]').val());
        // $('input.qty').val(qty).trigger('change');
        // $('.quantity input.qty').attr('step', iniStep).val(qty);

    });

    function updateCartWidth() {
        $('form.woocommerce-cart-form .quantity input[type=number]').each(function() {
            let cartqty = $(this).val();
            let cartqtyWidth = cartqty.toString().length +2.631;
            $(this).css('width', cartqtyWidth + 'em');
        });
    }

    updateCartWidth();
    $(document).on('change', 'form.woocommerce-cart-form .quantity input[type=number]', updateCartWidth);


});
