<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<section class="content-header">
    <h1><i class="fa fa-gavel"></i> <?php echo $page_title?></h1>
    <ol class="breadcrumb">
        <li><a href="<?php echo site_url('admin/diligencias')?>">Diligências</a></li>
        <li class="active"><?php echo $page_title?></li>
    </ol>
</section>
<section class="content">
<div class="row"><div class="col-md-10 col-md-offset-1">
<div class="box box-primary">
    <div class="box-header with-border"><h3 class="box-title">Dados da Diligência</h3></div>
    <form method="post" action="<?php echo site_url('admin/diligencias/add/'.($diligencia->id??0))?>">
    <div class="box-body">
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label>Título <span class="text-danger">*</span></label>
                    <input type="text" name="titulo" class="form-control" required value="<?php echo htmlspecialchars($diligencia->titulo??'')?>">
                </div>
            </div>
            <div class="col-md-3">
                <div class="form-group">
                    <label>Tipo <span class="text-danger">*</span></label>
                    <select name="tipo" class="form-control" required>
                        <?php foreach(['audiencia'=>'Audiência','pericia'=>'Perícia','despacho'=>'Despacho','protocolo'=>'Protocolo','citacao'=>'Citação','intimacao'=>'Intimação','sustentacao'=>'Sustentação Oral','outro'=>'Outro'] as $v=>$l): ?>
                        <option value="<?php echo $v?>" <?php echo ($diligencia->tipo??'')===$v?'selected':''?>><?php echo $l?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="col-md-3">
                <div class="form-group">
                    <label>Status</label>
                    <select name="status" class="form-control">
                        <option value="agendada" <?php echo ($diligencia->status??'agendada')==='agendada'?'selected':''?>>Agendada</option>
                        <option value="em_andamento" <?php echo ($diligencia->status??'')==='em_andamento'?'selected':''?>>Em Andamento</option>
                        <option value="concluida" <?php echo ($diligencia->status??'')==='concluida'?'selected':''?>>Concluída</option>
                        <option value="cancelada" <?php echo ($diligencia->status??'')==='cancelada'?'selected':''?>>Cancelada</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-4">
                <div class="form-group">
                    <label>Data e Hora da Diligência</label>
                    <input type="datetime-local" name="data_hora" class="form-control" value="<?php echo $diligencia&&$diligencia->data_hora?date('Y-m-d\TH:i',strtotime($diligencia->data_hora)):''?>">
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    <label>Prazo Fatal</label>
                    <input type="date" name="data_prazo" class="form-control" value="<?php echo $diligencia->data_prazo??''?>">
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    <label>Local / Vara / Tribunal</label>
                    <input type="text" name="local" class="form-control" placeholder="Ex: 3ª Vara Cível do Recife" value="<?php echo htmlspecialchars($diligencia->local??'')?>">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-4">
                <div class="form-group">
                    <label>Processo vinculado</label>
                    <select name="case_id" class="form-control chzn">
                        <option value="">Nenhum</option>
                        <?php foreach($cases as $c): ?>
                        <option value="<?php echo $c->id?>" <?php echo ($diligencia->case_id??'')==$c->id?'selected':''?>><?php echo htmlspecialchars($c->case_no.' - '.$c->title)?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    <label>Cliente</label>
                    <select name="client_id" class="form-control chzn">
                        <option value="">Nenhum</option>
                        <?php foreach($clientes as $c): ?>
                        <option value="<?php echo $c->id?>" <?php echo ($diligencia->client_id??'')==$c->id?'selected':''?>><?php echo htmlspecialchars($c->name)?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    <label>Advogado Responsável</label>
                    <select name="responsavel_id" class="form-control">
                        <option value="">Nenhum</option>
                        <?php foreach($advogados as $a): ?>
                        <option value="<?php echo $a->id?>" <?php echo ($diligencia->responsavel_id??'')==$a->id?'selected':''?>><?php echo htmlspecialchars($a->name)?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-9">
                <div class="form-group">
                    <label>Descrição / Observações</label>
                    <textarea name="descricao" class="form-control" rows="3"><?php echo htmlspecialchars($diligencia->descricao??'')?></textarea>
                </div>
            </div>
            <div class="col-md-3">
                <div class="form-group">
                    <label>Custo da Diligência (R$)</label>
                    <div class="input-group">
                        <span class="input-group-addon">R$</span>
                        <input type="text" name="valor_custo" class="form-control" value="<?php echo number_format($diligencia->valor_custo??0,2,',','.')?>" placeholder="0,00">
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" name="submitted" value="1">
    </div>
    <div class="box-footer">
        <button type="submit" class="btn btn-primary btn-lg"><i class="fa fa-save"></i> Salvar</button>
        <a href="<?php echo site_url('admin/diligencias')?>" class="btn btn-default btn-lg">Cancelar</a>
    </div>
    </form>
</div>
</div></div>
</section>
