<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#notificarTelegram").click(function(){
            if($(this).is(':checked')){
                $("#idTelegramLabel").css('display', 'block');
                $("#idTelegram").css('display', 'block');
            }else{
                $("#idTelegramLabel").css('display', 'none');
                $("#idTelegram").css('display', 'none');
            }
        });
    });
</script>
<div class="row">
    <div class="col-md-6">
        @isset($funcionario)
            <input type="hidden" name="id" value="{{$funcionario->id}}">
        @endisset
        <div class="form-group {{ $errors->has('name') ? 'has-error' : '' }}">
            <label for="name" class="control-label">{{ 'Nome' }}</label>
            <input class="form-control" name="name" type="text" id="name"
                value="@isset($funcionario) {{ $funcionario->name }} @endisset">
            {!! $errors->first('name', '<p class="help-block">:message</p>') !!}
        </div>
        <div class="form-group {{ $errors->has('email') ? 'has-error' : '' }}">
            <label for="email" class="control-label">{{ 'Email' }}</label>
            <input class="form-control" name="email" type="email" id="email"
                value="@isset($funcionario) {{ $funcionario->email }} @endisset">
            <div class="form-check">
                <label class="form-check-label">
                    <input type="checkbox" class="form-check-input" name="notificarEmail" value="" @isset($funcionario) {{ $funcionario->notificarEmail == 1 ? 'checked' : '' }} @endisset>Receber notificações por e-mail
                </label>
            </div>
            {!! $errors->first('email', '<p class="help-block">:message</p>') !!}
        </div>

        <div class="form-group {{ $errors->has('cpf') ? 'has-error' : '' }}">
            <label for="cpf" class="control-label">{{ 'CPF' }}</label>
            <input class="form-control" name="cpf" type="text" id="cpf"
                value="@isset($funcionario) {{ $funcionario->cpf }} @endisset">
            {!! $errors->first('cpf', '<p class="help-block">:message</p>') !!}
        </div>
        <div class="form-group {{ $errors->has('nivel') ? 'has-error' : '' }}">
            <label for="nivel" class="control-label">{{ 'Nível' }}</label>
            <select name="nivel" id="nivel" class="form-control">
                <option>Nível do funcionário</option>
                <option value="1" @if (isset($funcionario) && $funcionario->nivel == 1) {{ ' selected' }}@endif>Cadastrador</option>
                <option value="2" @if (isset($funcionario) && $funcionario->nivel == 2) {{ ' selected' }}@endif>Funcionário Comum</option>
            </select>
            {!! $errors->first('nivel', '<p class="help-block">:message</p>') !!}
        </div>
    </div>
    <div class="col-md-6">
        <div class="form-group {{ $errors->has('cargo') ? 'has-error' : '' }}">
            <label for="cargo" class="control-label">{{ 'Cargo' }}</label>
            <input class="form-control" name="cargo" type="text" id="cargo"
                value="@isset($funcionario) {{ $funcionario->cargo }} @endisset">
            {!! $errors->first('cargo', '<p class="help-block">:message</p>') !!}
        </div>
        <div class="form-group {{ $errors->has('matricula') ? 'has-error' : '' }}">
            <label for="matricula" class="control-label">{{ 'Matrícula' }}</label>
            <input class="form-control" name="matricula" type="text" id="matricula"
                value="@isset($funcionario) {{ $funcionario->matricula }} @endisset">
            {!! $errors->first('matricula', '<p class="help-block">:message</p>') !!}
        </div>
        <div class="form-group {{ $errors->has('idTelegram') ? 'has-error' : '' }}">
            <div class="form-check">
                <label class="form-check-label">
                    <input id="notificarTelegram" type="checkbox" class="form-check-input" name="notificarTelegram" value="">Receber notificações via Telegram
                </label>
            </div>
            <label id="idTelegramLabel" for="idTelegram" class="control-label" style="display: none">{{ 'ID do Telegram' }}</label>
            <input class="form-control" name="idTelegram" type="text" id="idTelegram"
                value="@isset($funcionario) {{ $funcionario->idTelegram }} @endisset" style="display: none">
            {!! $errors->first('idTelegram', '<p class="help-block">:message</p>') !!}
        </div>
        <div class="form-group {{ $errors->has('idSetor') ? 'has-error' : '' }}">
            <label for="cargo" class="control-label">{{ 'Setor' }}</label>
            <select name="idSetor" id="idSetor" class="form-control">
                <option value="0">Escolha o Setor</option>
                @foreach ($setores as $indice => $setor)
                    <option value="{{ $indice }}" @if (isset($funcionario) && $funcionario->idSetor == intval(trim($indice, "'")) ) {{ ' selected' }}@endif>{{ $setor }}</option>
                @endforeach
            </select>
            {!! $errors->first('setor', '<p class="help-block">:message</p>') !!}
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-info">
                @if ($formMode == 'create')
                    {{ 'Criar' }}
                @else
                    {{ 'Editar' }}
                @endif
            </button>
        </div>
