@extends('adminlte::page')

@section('title', 'IPRS | Multistep Registration')

@section('plugins.Select2', true)

@section('content_header')
    <div class="col-9 mx-auto d-flex justify-content-between align-items-center">
        <div class="row">
            <div class="col-sm-8 px-0">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
                    <li class="breadcrumb-item"><a href="{{ route('sub-account.index') }}">Organization Users</a></li>
                    <li class="breadcrumb-item active">New User</li>
                </ol>
            </div>
            <div class="col-sm-12">
                <h1 class="m-0">Add organization users to contract</h1>
            </div>
        </div>
    </div>
@stop

@section('content')
    @php use App\Models\Contract; @endphp

    <div class="col-9 mx-auto">
        <form action="{{ route('sub-account.store') }}@yield('id')" method="post">
            @csrf
            @section('method')@show
            <fieldset>
                <legend>Fill the following fields to create a new User</legend>
                <div class="row">
                    <x-adminlte-select2 name="contract_id" label="Select a Contract" placeholder="Select a contract"
                                        fgroup-class="col-md-6" id="contract-select" enable-old-support>
                        <option value="">Select a Contract</option>
                        @foreach($contracts as $contract)
                            <option @selected(isset($user) && $user->contract_rid == $contract->rid) value="{{ $contract->rid }}">
                                {{ $contract->client->name_fl }} - Contract No. {{ $contract->rid }}
                            </option>
                        @endforeach
                    </x-adminlte-select2>

                    <x-adminlte-input name="name" label="Name" placeholder="Full Name"
                                      value="{{ $user->name ?? old('name') }}"
                                      fgroup-class="col-md-6"/>

                    <x-adminlte-input name="email" label="Email" placeholder="E-mail Address"
                                      value="{{ $user->email ?? old('email') }}"
                                      fgroup-class="col-md-6"/>

                    {{--<x-adminlte-input type="password" name="password" label="Password" placeholder="Password"
                                      fgroup-class="col-md-6"/>--}}

                    <x-adminlte-select id="status" name="status" label="Select a status"
                                       placeholder="Select a status" fgroup-class="col-md-6" enable-old-support>
                        <option value="">Select a Status</option>
                        <option @selected(isset($user) && $user->status_l == "1") value="1">Active (1)</option>
                        <option @selected(isset($user) && $user->status_l == "0") value="0">Inactive (0)</option>
                    </x-adminlte-select>

                    <div class="col-6">
                        <label>Role(s)</label>
                        @foreach($roles as $role)
                            <div class="icheck-primary" title="{{ $role->name }}" @if($role->for_contract) style="display: none" @endif>
                                <input type="checkbox" @checked((isset($contract) && $role->name == 'CID-'.$contract->rid) || (isset($user) && $user->hasRole($role->name)))
                                name="role[]" value="{{ $role->name }}"
                                       id="role-{{ $loop->index }}">

                                <label for="role-{{ $loop->index }}" class="font-weight-normal">
                                    {{ $role->name }}
                                    <p class="text-muted small">
                                        <em>Check if the user is going to be part of contract administration.</em>
                                    </p>
                                </label>
                            </div>
                        @endforeach
                    </div>
                    <div class="col-6">
                        @section('resetField')@show
                    </div>
                </div>
                <div class="d-flex justify-content-end align-content-end mb-3">
                    <button type="submit" class="btn btn-success">Submit</button>
                </div>
            </fieldset>
        </form>
    </div>
@stop

@section('css')
    <style>
        fieldset {
            background-color: white;
            padding-block-start: 0.35em;
            padding-inline-start: 1.25em;
            padding-inline-end: 1.25em;
            padding-block-end: 0.625em;
            margin: 0 0 1em 0;
            border: 1px groove rgb(192, 192, 192);
            border-radius: 5px;
        }

        legend {
            background-color: #356eac;
            color: white;
            width: auto;
            font-size: medium;
            padding: 5px 10px;
            border-radius: 5px;
        }

        .form-check{
            padding-left: 2.25rem;
        }

        .content-header .breadcrumb{
            padding-left: 10px;
        }

        .select2-container .select2-selection--single{
            height: unset;
        }

        .select2-container--default .select2-selection--single .select2-selection__arrow{
            height: 38px;
        }
    </style>
@stop

@section('js')@stop

@section('plugins.Select2', true)

@section('plugins.iCheck', true)
