<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    @include('layout.header')
    <style>
        .box-action-buttons {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }

        .box-action-buttons .btn {
            width: 34px;
            height: 30px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 0;
            margin-right: 0 !important;
        }

        .box-action-buttons .btn i {
            line-height: 1;
            margin: 0;
        }
    </style>
</head>
<body>
<div class="container-scroller">
@include('layout.navbar')
@include('layout.breadscrum')
    <div class="container-fluid page-body-wrapper">
    @include('layout.sidebar')
        <div class="main-panel">
            <div class="content-wrapper">
                <div class="row">
                    <div class="col-md-12 grid-margin stretch-card">
                        <div class="card" style="min-height: 80vh;">
                            <div class="card-body">
                                <h4 class="card-title"><i class="mdi mdi-dots-vertical menu-icon"></i> {{__('general.sample_box')}}</h4>
                                <form method="get" action="{{url('box/search')}}">
                                    <div class="row">
                                        <div class="col-xs-12 col-sm-12 col-md-9 col-lg-9">
                                            <div class="input-group">
                                                <input type="text" class="form-control form-control-md rounded-left-25 rounded-right-0" value="{{isset($_GET['kword']) ? $_GET['kword'] : ''}}" name="kword" id="kword" placeholder="{{__('laboratory.search_placeholder')}}">
                                                <div class="input-group-append">
                                                    <select class="form-control select2 rounded-left-0 rounded-right-0" name="rack_id" style="width: 280px !important;">
                                                        <option></option>
                                                        @foreach($racks as $rack)
                                                            <option {{@$_GET['rack_id']==$rack->id ? 'selected':''}} value="{{$rack->id}}">
                                                                {{optional($rack->equipment)->name}} / {{$rack->name}}
                                                            </option>
                                                        @endforeach
                                                    </select>
                                                    <button class="btn btn-md btn-inverse-secondary rounded-right-25 px-3" type="submit"><i class="fa fa-search"></i>&nbsp;{{__('general.btn_search')}}</button>
                                                    <button class="btn btn-md btn-inverse-success waves-effect rounded-25 px-4 ml-3" type="button" data-action="new" data-toggle="modal" data-target="#modal-box" data-backdrop="static"><i class="typcn typcn-plus"></i> {{__('general.btn_add_new')}}</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                                <div class="col-sm-12 p-0 mb-1 mt-3">
                                    <div class="table-responsive">
                                        <table class="table table-bordered table-striped table-hover">
                                            <thead>
                                            <tr class="bg-gradient-light">
                                                <th class="py-2" width="50px">{{__('laboratory.table_no')}}</th>
                                                <th class="py-2 text-center" width="150px">{{__('laboratory.table_action')}}</th>
                                                <th class="py-2" width="120px">{{__('general.code')}}</th>
                                                <th class="py-2">{{__('general.name')}}</th>
                                                <th class="py-2">{{__('general.rack')}}</th>
                                                <th class="py-2">{{__('general.rows')}}</th>
                                                <th class="py-2">{{__('general.columns')}}</th>
                                                <th class="py-2">{{__('general.capacity')}}</th>
                                                <th class="py-2 text-center" width="100px">{{__('laboratory.table_status')}}</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            @foreach($boxes as $k=>$box)
                                                <tr>
                                                    <td class="py-1 text-center">{{($k+1) + (($_GET['page'] ?? 1) * 20) - 20}}</td>
                                                    <td class="text-center py-1">
                                                        <div class="box-action-buttons" role="group">
                                                            <button type="button" class="btn btn-sm btn-inverse-primary" title="Edit" data-action="edit" data-box_id="{{$box->id}}" data-toggle="modal" data-target="#modal-box" data-backdrop="static"><i class="typcn typcn-edit"></i></button>
                                                            <a class="btn btn-sm btn-inverse-info" title="Box Map" href="{{url('box/'.$box->id.'/positions')}}"><i class="mdi mdi-grid"></i></a>
                                                            @if($box->record_status_id==0)
                                                                <button type="button" class="btn btn-sm btn-inverse-primary" title="Restore" onclick="restore_lab({{$box->id}})"><i class="typcn typcn-plus"></i></button>
                                                            @else
                                                                <button type="button" class="btn btn-sm btn-inverse-danger" title="Delete" onclick="delete_lab({{$box->id}})"><i class="mdi mdi-close-circle"></i></button>
                                                            @endif
                                                        </div>
                                                    </td>
                                                    <td class="py-1">{{$box->code}}</td>
                                                    <td class="py-1">{{$box->name}}</td>
                                                    <td class="py-1">{{optional(optional($box->rack)->equipment)->name}} / {{optional($box->rack)->name}}</td>
                                                    <td class="py-1">{{$box->rows}}</td>
                                                    <td class="py-1">{{$box->columns}}</td>
                                                    <td class="py-1">{{$box->capacity}}</td>
                                                    <td class="py-1 text-center"><i class="mdi {{$box->record_status_id == 1 ? 'mdi-check-circle text-primary' : 'mdi-checkbox-blank-circle-outline'}}"></i></td>
                                                </tr>
                                            @endforeach
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="float-right mt-3">
                                    {!! $boxes->links('pagination.custom') !!}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal mt-5 fade modal-primary" id="modal-box">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h6 class="modal-title">{{__('_')}}</h6>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" class="mdi mdi-close"></span></button>
                        </div>
                        <div class="modal-body">
                            <form method="post" action="#" id="form" onkeydown="return event.key != 'Enter';">
                                @csrf
                                <input type="hidden" class="form-control" name="box_id" id="box_id" value="0" />
                                <div class="form-vertical">
                                    <div class="row">
                                        <div class="col-sm-6">
                                            <div class="form-group mb-1">
                                                <label>{{__('general.code')}} <span class="text-danger">*</span></label>
                                                <input type="text" class="form-control" name="code" id="code" value="" />
                                            </div>
                                        </div>
                                        <div class="col-sm-6">
                                            <div class="form-group mb-1">
                                                <label>{{__('general.box_name')}} <span class="text-danger">*</span></label>
                                                <input type="text" class="form-control" name="name" id="name" value="">
                                            </div>
                                        </div>
                                        <div class="col-sm-12">
                                            <div class="form-group mb-1">
                                                <label>{{__('general.rack')}} <span class="text-danger">*</span></label>
                                                <select class="form-control select2" name="rack_id" id="rack_id" style="width: 100% !important;">
                                                    <option></option>
                                                    @foreach($racks as $rack)
                                                        <option value="{{$rack->id}}">{{optional($rack->equipment)->name}} / {{$rack->name}}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-sm-4">
                                            <div class="form-group mb-1">
                                                <label>{{__('general.rows')}} <span class="text-danger">*</span></label>
                                                <input type="number" class="form-control" name="rows" id="rows" value="">
                                            </div>
                                        </div>
                                        <div class="col-sm-4">
                                            <div class="form-group mb-1">
                                                <label>{{__('general.columns')}} <span class="text-danger">*</span></label>
                                                <input type="number" class="form-control" name="columns" id="columns" value="">
                                            </div>
                                        </div>
                                        <div class="col-sm-4">
                                            <div class="form-group mb-1">
                                                <label>{{__('general.capacity')}}</label>
                                                <input type="number" class="form-control" name="capacity" id="capacity" value="" placeholder="auto">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-success rounded-25" id="btnSave"><i class="fa fa-floppy-o"></i>&nbsp;&nbsp;<span class="save">{{__('lang.save')}}</span><span class="update" style="display: none">{{__('lang.update')}}</span></button>
                            <button type="button" class="btn btn-secondary rounded-25 ml-2" data-dismiss='modal'>{{__('lang.cancel')}}</button>
                        </div>
                    </div>
                </div>
            </div>
            @include('layout.footer')
        </div>
    </div>
</div>
@include('layout.common_script')
<script>
    var save_url = "{{url('box.save')}}";
    var update_url = "{{url('box.update')}}";
    var delete_url = "{{url('box.delete')}}";
    var restore_url = "{{url('box.restore')}}";
    var get_url = "{{url('box.get')}}";
    let modal_add_title = "Add Box";
    let modal_edit_title = "Edit Box";
</script>
<script src="{{url(env("APP_URL").'storage/assets/js/admin/box.js?_').time()}}"></script>
</body>
</html>
