@extends ('layouts/template')
@section('content')

    <div class="p-3 mcp-theme-1">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <div class="d-flex align-items-baseline">
                            <div>
                                <h6 class="font-weight-bold mb-0"><i class="fas fa-network-wired"></i> Stat Trees</h6>
                            </div>
                            <div moe relative wide class="ml-auto">
                                <a href="#" start show class="btn btn-sm btn-primary text-white">Create Tree</a>
                                <form url="{{ route("practice-management.api.statTree.create") }}"
                                      right
                                      redir="/practice-management/stat-trees/view/[data]/edit">
                                    @csrf
                                    <div class="mb-2">
                                        <label class="text-secondary text-sm mb-1">Name *</label>
                                        <input type="text" class="form-control form-control-sm" name="name" autofocus required>
                                    </div>
                                    <div class="mb-2">
                                        <label class="text-secondary text-sm mb-1">Model *</label>
                                        <input type="text" class="form-control form-control-sm" data-option-list="model-options" autocomplete="off" name="model" required>
                                        <div id="model-options" class="data-option-list">
                                            <?php $models = \Illuminate\Support\Facades\DB::select('SELECT distinct(model) as m FROM clause order by model'); ?>
                                            @foreach($models as $m)
                                                <div>{!! $m->m !!}</div>
                                            @endforeach
                                        </div>
                                    </div>
                                    <div class="mb-2">
                                        <label class="text-secondary text-sm mb-1">Slug *</label>
                                        <input type="text" class="form-control form-control-sm" name="slug" required>
                                    </div>
                                    <label class="my-3 d-flex align-items-center">
                                        <span class="mr-2">Is Template?</span>
                                        <input type="checkbox" name="isTemplate">
                                    </label>
                                    <div class="mb-2">
                                        <label class="text-secondary text-sm mb-1">Pro</label>
                                        <select name="proUid" class="form-control input-sm" provider-search provider-type="hcp">
                                            <option value="">--select--</option>
                                        </select>
                                    </div>
                                    <div class="mb-2">
                                        <label class="text-secondary text-sm mb-1">Pro Scope Clause</label>
                                        <input type="text" class="form-control form-control-sm" name="proScopeClause">
                                    </div>
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-primary mr-2" type="button" submit>Save</button>
                                        <button class="btn btn-sm btn-default mr-2 border" type="button" cancel>Cancel</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div class="card-body p-0">
                        <table class="table table-condensed p-0 m-0">
                            <thead class="bg-light">
                            <tr>
                                <th class="border-0">ID</th>
                                <th class="border-0">Name</th>
                                <th class="border-0">Model</th>
                                <th class="border-0">Slug</th>
                                <th class="border-0">Pro</th>
                                <th class="border-0"></th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($statTrees as $statTree)
                                <tr>
                                    <td>{{ $statTree->id }}</td>
                                    <td><a href="{{ route('practice-management.statTrees.view.edit', $statTree) }}">{{ $statTree->name }}</a>
                                        @if($statTree->is_template)
                                            <span class="mt-1 text-sm bg-info rounded text-white d-inline-block px-2 py-1 ml-1 font-weight-bold">TEMPLATE</span>
                                        @endif
                                    </td>
                                    <td>{{ $statTree->model }}</td>
                                    <td>{{ $statTree->slug }}</td>
                                    <td>
                                        @if($statTree->pro)
                                            {{$statTree->pro->displayName()}}
                                        @endif
                                        @if($statTree->pro_scope_clause)
                                            <div class="text-secondary text-sm">{{$statTree->pro_scope_clause}}</div>
                                        @endif
                                    </td>
                                    <td>
                                        <div class="d-flex align-items-baseline">
                                            <a href="{{ route('practice-management.statTrees.view.edit', $statTree) }}">Edit</a>
                                            @if($statTree->is_template)
                                                <span class="mx-2 text-secondary text-sm">|</span>
                                                <div moe relative>
                                                    <a href="#" start show class="text-nowrap">Inst.</a>
                                                    <form url="{{ route('practice-management.statTrees.instantiate', $statTree) }}" right redir="/practice-management/stat-trees/view/[data]/edit">
                                                        @csrf
                                                        <p class="mb-2 font-weight-bold">Instantiate for Pro</p>
                                                        <div class="mb-2">
                                                            <label class="text-sm mb-1">Pro</label>
                                                            <select name="proUid" class="form-control input-sm" provider-search provider-type="hcp">
                                                                <option value="">--select--</option>
                                                            </select>
                                                        </div>
                                                        <div class="d-flex align-items-center">
                                                            <button class="btn btn-sm btn-primary mr-2" type="button" submit>Save</button>
                                                            <button class="btn btn-sm btn-default mr-2 border" type="button" cancel>Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                                <span class="mx-2 text-secondary text-sm">|</span>
                                                <div moe relative>
                                                    <a href="#" start show class="text-nowrap">Clone</a>
                                                    <form url="{{ route('practice-management.statTrees.clone', $statTree) }}" right redir="/practice-management/stat-trees/view/[data]/edit">
                                                        @csrf
                                                        <p class="mb-2 font-weight-bold">Clone</p>
                                                        <div class="mb-2">
                                                            <label class="text-sm mb-1">Name</label>
                                                            <input type="text" name="name" class="form-control form-control-sm" value="{{$statTree->name}} (clone)" required>
                                                        </div>
                                                        <div class="d-flex align-items-center">
                                                            <button class="btn btn-sm btn-primary mr-2" type="button" submit>Save</button>
                                                            <button class="btn btn-sm btn-default mr-2 border" type="button" cancel>Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            @endif
                                            <span class="mx-2 text-secondary text-sm">|</span>
                                            <div moe relative>
                                                <a href="#" start show class="text-nowrap"><i class="text-danger on-hover-opaque fa fa-trash-alt"></i></a>
                                                <form url="{{ route('practice-management.api.statTree.remove', $statTree) }}" right>
                                                    @csrf
                                                    <input type="hidden" name="uid" value="{{$statTree->uid}}">
                                                    <p class="mb-2 font-weight-bold">Remove this tree?</p>
                                                    <div class="d-flex align-items-center">
                                                        <button class="btn btn-sm btn-danger mr-2" type="button" submit>Delete</button>
                                                        <button class="btn btn-sm btn-default mr-2 border" type="button" cancel>Cancel</button>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

@endsection