<?php
$cancellationstring = "";
?>
    <div class="col-sm-12">
        <h5>Commission Rate</h5>
        <div class="col-sm-12" style="margin-left: 160px;">                  
                <div class="row">
                    <div class="col-sm-4">
                        <label><?php echo $this->translate($form->get('netrate_commissionrate[]')->getLabel()); ?></label>
                    </div>
                    <div class="col-sm-2">
                        <label><?php echo $this->translate($form->get('commission_rate_type[]')->getLabel()); ?></label>
                    </div>
                    <div class="col-sm-2">
                        <label><?php echo $this->translate($form->get('commission_rate_value[]')->getLabel()); ?></label>
                    </div>

                    <div class="col-sm-3"></div>
                    <div class="col-sm-3">&nbsp;</div>
                </div>


                <div id="CancellationfeesDiv_package">
                    <div class="row form-group">
                        <div class="col-sm-4"><?php echo $this->formElement($form->get('netrate_commissionrate[]')->setValue('')); ?></div>
                        <div class="col-sm-2"><?php echo $this->formElement($form->get('commission_rate_type[]')->setValue('')); ?></div>
                        <div class="col-sm-2">
                            <div class="input-group"><?php echo $this->formElement($form->get('commission_rate_value[]')->setValue('')); ?></div>
                        </div>



                        <div class="col-sm-2">
                            <div class="addcancellation_on_plus no-padding" id="addprewaiting_3">
                                <a href="#" class="btn btn-info form-control">Add More</a>
                            </div>
                        </div>

                        <div class="col-sm-1"></div>
                    </div>

                </div>

                <div id="appended_cancellationfees_package"></div>
                <?php echo $cancellationstring; ?>
                <hr>
        </div>
        <div class="col-sm-4 col-md-4"></div>
    </div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).on('click', '.addcancellation_on_plus', function () {
        var addButtonId = $(this).attr('id');
        var counterArr = addButtonId.split("_");
        var counter = counterArr[1];
        counter++;
        var cancellation_master = '<?php echo str_replace("\n", '\n', $this->formElement($form->get('netrate_commissionrate[]'))); ?>';
        var cancellation_type = '<?php echo str_replace("\n", '\n', $this->formElement($form->get('commission_rate_type[]'))); ?>';
        var cancellation_price = '<?php echo $this->formElement($form->get('commission_rate_value[]')); ?>';
        // $("#" + addButtonId).remove();
        var detailsdiv = "";
        detailsdiv += '<div class="row form-group" style="margin-top:10px;"><div class="col-sm-4">' + cancellation_master + '</div><div class="col-sm-2">' + cancellation_type + '</div><div class="col-sm-2"><div class="input-group">' + cancellation_price + '</div></div><div class="col-sm-1 remove_cancellationfees_row"><a href="#"  id="removePreWaitingPkgFields_' + counter + '"><i class="fa fa-trash-o fa-2x"></i></a></div></div>';
        //appendedPreWaitingTimeLength++;
        $("#appended_cancellationfees_package").append(detailsdiv);
        $(".datepicker").datepicker({
            changeYear: true,
            changeMonth: true,
            minDate: 0,
            yearRange: "-100:+20",
            dateFormat: "d-m-yy",
        });
        checkTheDropdowns();
        return false;
    });


    $(document).on('click', '.remove_cancellationfees_row', function () {
        var addId = $(".addcancellation_on_plus").attr('id');
        var addIdArr = addId.split("_");
        var counter = addIdArr[1];
        counter--;
        $(this).closest('.row').remove();
        var addbtn_length = $("#appended_cancellationfees_package .addcancellation_on_plus").length;
        var row_leng = $("#appended_cancellationfees_package .row").length;
        //appendedPreWaitingTimeLength--;
        checkTheDropdowns();
        return false;
    });

    /*$(document).on('change', '.cancel-master', checkTheDropdowns);
    $(document).on('click', '.cancel-master', checkTheDropdowns);
    function checkTheDropdowns() {
        var arr = $('.cancel-master').find(':selected');
        $('.cancel-master').find('option').show();
        $.each($('.cancel-master'), function () {
            var self = this;
            var selectVal = $(this).val();
            $.each(arr, function () {
                if (selectVal !== $(this).val()) {
                    $(self).find('option[value="' + $(this).val() + '"]').hide()
                } else {
                    $(self).find('option[value="' + $(this).val() + '"]').show()
                }
            });
        })
    }*/
    
    $(document).on('change', '.cancel-master', checkTheDropdowns);
    function checkTheDropdowns() {
        var rateType = $(this).val();
        //alert(rateType);
        if(rateType=="Net Rate"){
            $(this).parent().parent().find('#comission-rate-type').
        }

    }


</script>

