<section class="content">
    <div class="row">
        <div class="col-sm-12">
            <div class="tabbable">
                <div class="tab-content no-border padding-24">
                    <div class="tab-pane fade in active" id="faq-tab-1">
                        <div class="space-8"></div>
                        <div class="panel-group accordion-style1 accordion-style2" id="faq-list-1">
                            <div class="panel panel-default">
                                <div class="panel-headingnew"><?php echo $this->translate('Cancellation Policy'); ?> </div>
                                <div class="left_panel col-sm-12 padding_margin0 pull-left bgwhite">
                                    <?php echo $this->partial('cancel-fees-sidebar.phtml'); ?>
                                    <div class="tab-content tab_editprofile col-sm-10 padding-left0 marginbott10px margintop10px">
                                        <div id="common-tab" class="tab-pane fade in tab_editprofile tab_editprofile1 active">
                                            <div class="col-sm-col-sm-offset-1 margin-10auto0 paddingRL10px">
<?php
$form = $this->form;
$form->prepare();
$form->setAttribute('action', $this->url('setting', ['action' => 'add-fees-fare']));
$form->setAttribute('method', 'post');
echo $this->form()->openTag($form);

$cancellation_fare = isset($fareDetails['cancellation_fare']) ? $fareDetails['cancellation_fare'] : '';
$cancellationstring = "";

    if ($cancellation_fare != '') {
        //$waiting_fareArr  = json_decode($waiting_fee_upto);
        $cancellationstring = '';
        foreach ($cancellation_fare as $key => $value) {
            $counter = $key;
            //$kmRate  = explode('_',$value);
            $cancellationstring .= '<div class="row form-group"><div class="col-sm-4">' . $this->formElement($form->get('cancellation_master_id[]')->setValue($value['cancellation_master_id'])) . '</div><div class="col-sm-2">' . $this->formElement($form->get('cancellation_type[]')->setValue($value['cancellation_type'])) . '</div><div class="col-sm-2" ><div class="input-group">' . $this->formElement($form->get('cancellation_fees[]')->setValue($value['cancellation_value'])) . '</div></div><div class="col-sm-1 remove_cancellationfees_row"  id="removeDistanceFields_"' . $counter . '><a href="#"><i class="fa fa-trash-o fa-2x"></i></a></div></div>';
        }
    }
?>

                                                <div class="row">
                                                    <div class="col-sm-12">
                                                        <div class="col-sm-12 col-md-12">
                                                            <div class="portlet-body">
                                                                <h4 class="cancellationFees_distance">Cancellation Fees</h4>
                                                                <div class="row form-group">
                                                                    <div class="col-sm-3 form-group">                  
                                                                        <h4>Booking Type</h4>
                                                                        <?php echo $this->FormElement($form->get('booking_type')->setValue(isset($cancellation_fare[0]['booking_type']) ? $cancellation_fare[0]['booking_type'] : '')); ?>
                                                                    </div>
                                                                </div>
                                                                
                                                                <div class="row">

        <div class="col-sm-4">
            <label><?php echo $this->translate($form->get('cancellation_master_id[]')->getLabel()); ?></label>
        </div>
        <div class="col-sm-2">
            <label><?php echo $this->translate($form->get('cancellation_type[]')->getLabel()); ?></label>
        </div>
        <div class="col-sm-2">
            <label><?php echo $this->translate($form->get('cancellation_fees[]')->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('cancellation_master_id[]')->setValue('')); ?></div>
        <div class="col-sm-2"><?php echo $this->formElement($form->get('cancellation_type[]')->setValue('')); ?></div>
        <div class="col-sm-2">
        <div class="input-group"><?php echo $this->formElement($form->get('cancellation_fees[]')->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 class="row ">
                                                                    <div class="col-sm-3"></div>
                                                                    <div class="col-sm-3"></div>
                                                                    <div class="col-sm-2 pull-right margin-bttom10px">
                                                                        <?php echo $this->formElement($form->get('save')); ?>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-sm-4 col-md-4"></div>
                                                    </div>
                                                </div>

                                                <?php echo $this->form()->closeTag(); ?>

                                                <span class="checkbox_error"></span>                                                
                                                <div class="panel panel-default">
                                                    <div class="panel-headingnew"> View/Update Records </div>
                                                    <div id="faq-1-3" class="panel-collapse collapse in" aria-expanded="false">
                                                        <div class="box">
                                                            <!-- /.box-header -->
                                                            <div class="box-body table-responsive listing-data">
                                                                <?php echo $this->partial('fees-fare-listing.phtml'); ?>
                                                            </div>
                                                            <!-- /.box-body -->
                                                        </div>
                                                    </div>
                                                </div>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <br>
        <!-- /.widget-box -->
    </div>
    <!-- /.col -->
</section>
<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('cancellation_master_id[]'))); ?>';
        var cancellation_type = '<?php echo str_replace("\n", '\n', $this->formElement($form->get('cancellation_type[]'))); ?>';
        var cancellation_price = '<?php echo $this->formElement($form->get('cancellation_fees[]')); ?>';
        // $("#" + 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()
                }
            });
        })
    }


</script>

