<?php if(empty($screen_mode)):?>
    <div class="row">
        <div class="col-12 col-lg-4">
            <?php if(empty($screen_mode)){ ?>
                <input type="hidden" value="<?php echo $this->uri->segment(7); ?>" class="form-control" name="id">
                <button class="btn btn-success btn-sm btn-block"  <?php echo ($disabled || !empty($claims->is_submit))?'disabled':''; ?> 
                <?php if(!$disabled && empty($claims->is_submit)): ?>
                onclick="submitClaims(<?php echo $this->uri->segment(7);?>)"
                <?php endif; ?>
                >
                    <?php echo (!empty($claims->is_submit))?'claim submitted':'<i class="far fa-save"></i> submit claims'; ?> 
                </button>
            <?php } ?>
        </div>
    </div>
<?php endif;?>

<?php if(!empty($screen_mode) && $screen_mode == 'admin'): ?>
    <div class="btn-group">
    <?php if(!empty($claims)):?>
        <?php if($claims->status == 0): ?>
        <form action="<?php echo base_url('hr/claim/adminPaidClaim/');?>" method="post" id="paidClaim">
            <input type="hidden" value="<?php echo $this->uri->segment(7); ?>" class="form-control" name="claim_id" />
            <button class="btn btn-success btn-sm">Set claim as complete</button>
        </form>
        <?php endif; ?>
    <?php endif; ?>
        <?php if($this->session->userdata('user')['id'] == 164 || $this->session->userdata('user')['id'] == 316 || $this->session->userdata('user')['id'] == 364 ): ?>
        <button class="btn btn-danger btn-sm" onclick="unsubmit(<?php echo $this->uri->segment(7); ?>); " >Set claim as unsubmitted </button>
        <?php endif; ?>
    </div>
<?php endif; ?>

<?php //if(!empty($screen_mode) && $screen_mode == 'hod'): ?>
    <!-- <div class="row">
        <div class="col-12">
            <button class="btn btn-success" onclick="approve_all(<?php echo $this->uri->segment(7); ?>);"><i class="far fa-thumbs-up"  style="transform:scaleX(-1)"></i> Approve All</button>
        </div>
    </div>
 --><?php //endif;?>

<script>
    function submitClaims(id) 
    {   
        toastConfirm('Are you sure you want to submit this claim?',function(){
            $.ajax({
                url: '<?php echo base_url('hr/claim/submitClaim/'); ?>',
                type: 'POST',
                data:{
                    id:<?php echo $this->uri->segment(7); ?>,
                },
                dataType: 'JSON',
                success: function(data){
                    location.reload();
                },
                error:function(err){
                    iziToast.error({
                        title: 'Error',
                        message: 'Failed to submit claims.Please reload this page and resubmit your claim.'
                    });
                }
            });

        })
    }

    function approve_all(id) 
    {
        toastConfirm('Are you sure you want to approve all item in the claims',function(){
            $.ajax({
                url: '<?php echo base_url('hr/claim/hodApprove'); ?>',
                type: 'POST',
                data:{
                    claim_id:id,
                    status:1,
                },
                dataType: 'JSON',
                success: function(data){
                    location.reload();
                },
                error:function(err){
                    iziToast.error({
                        title: 'Error',
                        message: 'Failed to approve all items in the claims.Please reload this page and click on thumbs up to approve all claims.'
                    });
                }
            });
        });
    }

    function unsubmit(id) 
    {  
        toastConfirm('Are you sure you want to set this claim as unsubmitted, All approved claim will be reverted to draft',function(){
            
            $.ajax({
                url: '<?php echo base_url('hr/claim/unsubmit_claim'); ?>',
                type: 'POST',
                data:{
                    claim_id:id
                },
                dataType: 'JSON',
                success: function(data){
                    window.location.href="<?php echo base_url('hr/claim/adminClaimList'); ?>";
                }
            });
        });
    }

</script>