@extends('admin.layouts.app')
@section('panel')
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-body p-0">
                    <div class="table-responsive--md table-responsive">
                        <table class="table table--light style--two">
                            <thead>
                                <tr>
                                    <th>@lang('Name')</th>
                                    <th>@lang('Category')</th>
                                    <th>@lang('Price')</th>
                                    <th>@lang('Total Card')</th>
                                    <th>@lang('Sold')</th>
                                    <th>@lang('Available')</th>
                                    <th>@lang('Status')</th>
                                    <th>@lang('Action')</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($subcategories as $subcategory)
                                    <tr>
                                        <td>
                                            <div class="user thumb">
                                                <div class="thumb w-100">
                                                    <img src="{{ getImage(getFilePath('subcategory') . '/' . @$subcategory->image, getFileSize('subcategory')) }}">
                                                    <span> {{ $subcategory->name }}</span>
                                                </div>
                                            </div>
                                        </td>
                                        <td> {{ __($subcategory->category->name) }} </td>
                                        <td> {{ showAmount($subcategory->price) }} </td>
                                        <td> <span class="badge badge--primary">{{ $subcategory->cards->count() }} @lang('pcs')</span> </td>
                                        <td> <span class="badge badge--success">{{ $subcategory->cards()->whereNotNull('user_id')->count() }} @lang('pcs') </span></td>
                                        <td> <span class="badge badge--warning">{{ $subcategory->cards()->where('user_id',0)->count() }} @lang('pcs') </span></td>
                                        <td> @php echo $subcategory->statusBadge @endphp </td>
                                        <td>
                                            <div class="button--group">
                                                @php $subcategory->image_with_path = getImage(getFilePath('subcategory').'/'.$subcategory->image ,getFileSize('subcategory')); @endphp
                                                <button class="btn btn-sm btn-outline--primary editBtn cuModalBtn" data-resource="{{ $subcategory }}" data-modal_title="@lang('Edit subcategory')" data-has_status="1" type="button">
                                                    <i class="la la-pencil"></i>@lang('Edit')
                                                </button>
                                                @if ($subcategory->status == Status::DISABLE)
                                                    <button class="btn btn-sm btn-outline--success ms-1 confirmationBtn" data-action="{{ route('admin.subcategory.status', $subcategory->id) }}" data-question="@lang('Are you sure to enable this subcategory')?" type="button">
                                                        <i class="la la-eye"></i> @lang('Enabled')
                                                    </button>
                                                @else
                                                    <button class="btn btn-sm btn-outline--danger confirmationBtn" data-action="{{ route('admin.subcategory.status', $subcategory->id) }}" data-question="@lang('Are you sure to disable this subcategory')?" type="button">
                                                        <i class="la la-eye-slash"></i> @lang('Disabled')
                                                    </button>
                                                @endif
                                            </div>
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td class="text-muted text-center" colspan="100%">{{ __($emptyMessage) }}</td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>
                @if ($subcategories->hasPages())
                    <div class="card-footer py-4">
                        @php echo paginateLinks($subcategories) @endphp
                    </div>
                @endif
            </div><!-- card end -->
        </div>
    </div>

    <!--Cu Modal -->
    <div class="modal fade" id="cuModal" role="dialog" tabindex="-1">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title"></h5>
                    <button class="close" data-bs-dismiss="modal" type="button" aria-label="Close">
                        <i class="las la-times"></i>
                    </button>
                </div>
                <form action="{{ route('admin.subcategory.store') }}" method="POST" enctype="multipart/form-data">
                    @csrf
                    <div class="modal-body">

                        <div class="form-group">
                            <label>@lang('Name')</label>
                            <input class="form-control" name="name" type="text" required>
                        </div>
                        <div class="form-group">
                            <label>@lang('Category')</label>
                            <select class="select2 form-control" name="category_id">
                                <option value="" selected disabled>@lang('Select One')</option>
                                @foreach ($categories as $category)
                                    <option value="{{ $category->id }}">{{ __($category->name) }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="form-group">
                            <label>@lang('Price')</label>
                            <div class="input-group">
                                <input class="form-control" name="price" type="text" required>
                                <span class="input-group-text">{{ gs('cur_text') }}</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>@lang('Image')</label>
                            <x-image-uploader class="w-100" id="uploadLogo" name="image" type="subcategory" :required="true" />
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn--primary h-45 w-100" type="submit">@lang('Submit')</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <x-confirmation-modal />
@endsection

@push('script-lib')
    <script src="{{ asset('assets/admin/js/cu-modal.js') }}"></script>
@endpush

@push('breadcrumb-plugins')
    <x-search-form />

    <button class="btn btn-sm btn-outline--primary cuModalBtn" data-image_path="{{ getImage(getFilePath('subcategory'), getFileSize('subcategory')) }}" data-modal_title="@lang('Add New subcategory')" type="button">
        <i class="las la-plus"></i>@lang('Add New')
    </button>
@endpush
