<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <div>
                    <span class="card-title"><i class="ri-git-repository-line"></i> {{ __('extra_'.$type) }}</span>
                </div>
            </div>
            <div class="card-content">
                <form id="extraForm">
                    <input type="hidden" class="form-control" name="type" value="{{ $type }}">
                    <div class="row my-3">
                        <div class="col-12 mb-3">
                            <div class="form-group">
                                <label for="count">{{ beGetLang('extra_question_'.$type,['price' => $price.$currencie['cicon']]) }}</label>
                                <div class="form-input">
                                    <input type="text" class="form-control" name="count" id="count" value="0">
                                </div>
                            </div>
                        </div>
                        <div class="col-12 mb-3">
                            <div class="card card-blue">
                                <div class="card-content" id="priceHelper">

                                </div>
                            </div>
                        </div>
                        <div class="col-12 row-center row-flex">
                            <a href="#" class="btn btn-primary beCallRequestx" data-method="extra" data-form="extra">
                                {{ __('extra_approve') }}
                            </a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    var wait = false;
    var count = 0;
    var defalutprice = parseFloat("{{ $price }}");
    var icon = "{{ $currencie['cicon'] }}";
    var defaulttext = "{{ __('extra_count_'.$type) }}";
    $("#count").on("input",function(e){
        count = parseInt(e.currentTarget.value);
        calculatePrice();
    });
    function calculatePrice(){
        var price = (defalutprice*count)+icon;
        text = defaulttext.replace("{count}",count);
        text = text.replace("{price}",price);
        $("#priceHelper").html(text);
    }
    calculatePrice();
    $(".beCallRequestx").on("click",function(){
        if(!wait){
            wait = true;
            var item = $(this);
            var content = item.html();
            item.html('<span class="beSpinner"></span> Lütfen Bekleyiniz!');
            var method = item.data("method");
            var form = item.data("form");
            var data = item.data("data");
            var datacontent = "";
            if(form){
                datacontent = $("#"+form+"Form").serialize()+"&action="+method+"&upid={{ $userproduct['upid'] }}";
            }
            else{
                datacontent = data+"&action="+method+"&upid={{ $userproduct['upid'] }}";
            }
            $.ajax({
                url: "{{ beGetRoute('client.userproduct.userproduct.show.post') }}",
                type: "post",
                data: datacontent,
                dataType: "json",
                crossDomain: true,
                success: function(response){
                    wait = false;
                    item.html(content);
                    if(response.status){
                        $.Toast("Başarılı",response.message,"success");
                        if(response.url){
                            setTimeout(function(){
                                window.location.href = response.url;
                            },1000);
                        }
                        if(response.refresh){
                            setTimeout(function(){
                                location.reload();
                            },1000);
                        }
                    }
                    else{
                        $.Toast("Bir Sorun Oluştu",response.message,"error");
                    }
                }
            });	
            return false;
        }
        else{
            $.Toast("Bir Sorun Oluştu","İşlem devam ediyor lütfen bekleyiniz","error");
        }
    });
</script>