@extends('layouts.app')

@section('content')
    <section class="page-header row">
        <h2> Loyalty Programs </h2>
        <ol class="breadcrumb">
            <li><a href="{{ url('') }}"> Dashboard </a></li>
            <li class="active"> Loyalty Programs</li>
        </ol>
    </section>
    <div class="page-content row">
        <div class="page-content-wrapper no-margin">
            <h3 class="section-title">All Records</h3>
            <div class="sbox">

                <div class="sbox-content">
                    <!-- Toolbar Top -->
                    <div class="toolbar-top">
                        <div class="row">
                            <div class="col-lg-7 col-md-6">
                                <a href="{{ url('/manage/loyaltyprograms/create') }}" class="btn btn-primary btn-sm"
                                   title="{{ __('core.btn_create') }}"><i class=" fa fa-plus "></i> Create New </a>

                                @if($access['is_excel'] ==1)
                                    <div style="display: inline-flex">
                                        <button type="button" id="exportBtn" class="btn btn-success" onclick="moduleExport()" style="display: inline-flex; margin-left: 20px">Export CSV</button>
                                        <div id="exportError" class="text-danger" style="margin: auto 15px; display: none">Error while Exporting Data!</div>
                                    </div>
                                @endif
                            </div>

                            <div class="col-lg-5 col-md-6 text-right toolbar-right">
                            </div>
                        </div>
                    </div>
                    <!-- End Toolbar Top -->

                    <div class="row">
                        {!! (isset($search_map) ? $search_map : '') !!}
                    </div>

                    <!-- Table Grid -->
                    <div class="table-responsive">

                        <table class="table table-striped table-hover " id="storeDealsTable">
                            <thead>
                            <tr>
                                <th style="width: 3% !important;" class="number"> Rank</th>
                                <th style="width: 10% !important;">{{ __('core.btn_action') }}</th>
                                <th> Name</th>
                                <th> Bonus Amount ($)</th>
                                <th> Min Sale Count</th>
                                <th> Min Sale Amount ($)</th>
                            </tr>
                            </thead>

                            <tbody>
                            @foreach ($rowData as $row)
                                <tr>
                                    <td> {{ $row['rank'] }} </td>
                                    <td>
                                        <div class="actions">
                                            <ul class="actions-menu"
                                                style="list-style-type: none; margin: 0; padding-left: 0;">
                                                <li>
                                                    <a href="{{ url('/manage/loyaltyprograms/'.$row['id'].'/edit') }}"
                                                       data-toggle="tooltip"
                                                       class="tips action-edit  btn btn-sm btn-success btn-fs"
                                                       title="{{ __('core.btn_edit') }}"> <i class="fa fa-edit"></i>
                                                    </a>
                                                </li>
                                                <li>
                                                    <a onclick="DeleteI('{{ $row['id'] }}');"
                                                       class="tips action-delete btn btn-sm btn-danger btn-fs"
                                                       data-toggle="tooltip" title="{{ __('core.btn_remove') }}"> <i
                                                                class="fa fa-trash"></i>
                                                    </a>
                                                </li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td>{{$row['name']['en']}}</td>
                                    <td>{{$row['bonus_amount']}}</td>
                                    <td>{{$row['min_sale_count']}}</td>
                                    <td>{{$row['min_sale_amount']}}</td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                        <input type="hidden" name="action_task" value=""/>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        function DeleteI(chkid) {
            if (confirm('are u sure you want to delete this row?')) {
                $.ajax({
                    type: "DELETE",
                    url: "/manage/loyaltyprograms/" + chkid,
                    success: function () {
                        window.location.reload();
                    }
                });
            }
        }
    </script>
@stop
