@extends('layouts.app')

<?php
    $request = request();
    $victim = new App\Models\Victim;
    $tab = ""; $successmessage = $failureurl ="";
    $rawCaseRef = $request->id;
    $id = null;
    $caseRef = $rawCaseRef;
    if (!empty($rawCaseRef)) {
        $case = null;
        if (\Illuminate\Support\Str::isUuid((string) $rawCaseRef) && \Illuminate\Support\Facades\Schema::hasColumn((new App\Models\Victim())->getTable(), 'uuid')) {
            $case = App\Models\Victim::where('uuid', $rawCaseRef)->first();
        } else {
            $decoded = base64_decode($rawCaseRef, true);
            $numericId = ($decoded !== false && is_numeric($decoded)) ? $decoded : (is_numeric($rawCaseRef) ? $rawCaseRef : null);
            if ($numericId) {
                $case = App\Models\Victim::find($numericId);
            }
        }
        if ($case) {
            $id = $case->id;
            $caseRef = !empty($case->uuid) ? $case->uuid : $case->id;
        }
    }
    $tab = $request->tab;

    if(Empty($tab)){
        $tab = 'overview';
    }
    if($tab == 'overview'){
        $successurl = url("dataentry/update?tab=incident&stp=new");
        $successurlnxt = url('dataentry/update?tab='.$tab);
        $gotosuccess = true;
        $posturl = url("dataentry/updatevictimdata");
    }
    if($tab == 'incidents'){
        $successurl = url("dataentry/update?tab=perpetrator&stp=new");
        $successurlnxt = url('dataentry/update?tab='.$tab);
        $gotosuccess = true;
        $posturl = url("dataentry/updateincidentdata");
    }
    if($tab == 'perpetrator'){
        $successurl = url("dataentry/update?tab=witness&stp=new");
        $successurlnxt = url('dataentry/update?tab='.$tab);
        $gotosuccess = true;
        $posturl = url("dataentry/updateperpetrator");
    }
    if($tab == 'witness'){
        $successurl = url("dataentry/update?tab=action&stp=new");
        $successurlnxt = url('dataentry/update?tab='.$tab);
        $gotosuccess = true;
        $posturl = url("dataentry/updatewitness");
    }
    if($tab == 'action'){
        $successurl = url("dataentry/update?tab=incident&stp=new");
        $gotosuccess = true;
        $posturl = url("dataentry/updateaction");
    }
    if($tab == 'status'){
        $successurl = url("dataentry/update?tab=incident&stp=new");
        $gotosuccess = true;
        $posturl = url("dataentry/updatestatus");
    }
    $gotosuccess = false;
    if(!Empty($request->successurl)){
        $successurl = $request->successurl;
        $gotosuccess = true;
    }
?>
@section('content')
<div class="pcoded-content ngbvd-data-entry-shell">
    <div class="pcoded-inner-content">
        <div class="main-body">
            <div class="page-wrapper">
                <!-- Page-header start -->
                <div class="page-header card page-body ngbvd-card">
                    <div class="row align-items-end">
                        <div class="col-lg-8">
                            <div class="page-header-title">
                                <i class="icofont icofont icofont icofont-file-document bg-c-pink"></i>
                                <div class="d-inline">
                                    <h4 class="ngbvd-page-title">Incident Data</h4>
                                    <span class="ngbvd-page-subtitle">Capture survivor, incident, referral, witness and case-status information</span>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-4">
                            <div class="page-header-breadcrumb">
                                <ul class="breadcrumb-title">
                                    <li class="breadcrumb-item">
                                        <a href="index.html">
                                            <i class="icofont icofont-home"></i>
                                        </a>
                                    </li>
                                    <li class="breadcrumb-item"><a href="#!">Incident Data</a>
                                    </li>
                                    <li class="breadcrumb-item"><a href="#!">Data Entry</a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                        <hr>
                        <div class="row">
                            <div class="col-sm-12">
                                <span>@if(Session::has('message'))
                                <div class="alert alert-warning">
                                {{ Session::get('message') }}
                                </div>
                                @endif
                               </span>
                                <?php //if(!Empty($id)){ ?>
                                <ul class="nav nav-tabs tabs ngbvd-step-tabs ngbvd-tabs" role="tablist">
                                    <li class="nav-item">
                                        <a class="nav-link <?php echo $tab == 'overview' ? 'active' : ''; ?>" href="<?php echo url('dataentry/update?id='.$caseRef.'&tab=overview'); ?>" role="tab">General Information</a>
                                    </li>
                                    <li class="nav-item">
                                        <a class="nav-link <?php echo $tab == 'incidents' ? 'active' : ''; ?>" href="<?php echo url('dataentry/update?id='.$caseRef.'&tab=incidents'); ?>" role="tab">Incident Data</a>
                                    </li>
                                    <li class="nav-item">
                                        <a class="nav-link <?php echo $tab == 'perpetrator' ? 'active' : ''; ?>" href="<?php echo url('dataentry/update?id='.$caseRef.'&tab=perpetrator'); ?>" role="tab">perpetrator Information</a>
                                    </li>
                                    <li class="nav-item">
                                        <a class="nav-link <?php echo $tab == 'witness' ? 'active' : ''; ?>" href="<?php echo url('dataentry/update?id='.$caseRef.'&tab=witness'); ?>" role="tab">Witnesses</a>
                                    </li>
                                    <li class="nav-item">
                                        <a class="nav-link <?php echo $tab == 'action' ? 'active' : ''; ?>" href="<?php echo url('dataentry/update?id='.$caseRef.'&tab=action'); ?>" role="tab">Action Taken</a>
                                    </li>
                                    <li class="nav-item">
                                        <a class="nav-link <?php echo $tab == 'status' ? 'active' : ''; ?>" href="<?php echo url('dataentry/update?id='.$caseRef.'&tab=status'); ?>" role="tab">Case Status</a>
                                    </li>
                                </ul>

                                <?php //} ?>
                                <form id="indexform" class="form-horizontal ngbvd-form-section" method="POST" action="<?php echo $posturl; ?>">
                                    @csrf
                                    <input name="entityname" id="entityname" type="hidden" value="Incident" />
                                    <input type="hidden" id="action" name="action"value="" />
                                    <input type="hidden" id="id" name="id" value="<?php echo $caseRef; ?>" />
                                    <input name="successmessage" id="successmessage" type="hidden" value="<?php echo $successmessage; ?>" />
                                    <input type="hidden" id="<?php echo "SUCCESS_MESSAGE"; ?>" name="<?php echo "SUCCESS_MESSAGE"; ?>" value="<?php echo $successmessage; ?>" />
                                    <input type="hidden" id="<?php echo "URL_SUCCESS"; ?>" name="URL_SUCCESS" value="<?php echo base64_encode($successurl); ?>" />
                                    <input type="hidden" id="<?php echo "URL_FAILURE"; ?>" name="URL_FAILURE" value="<?php echo base64_encode($failureurl); ?>" />
                                    <input type="hidden" id="status" name="status" value="" />
                                    <input type="hidden" id="companyid" name="companyid" value="" />
                                    <input type="hidden" id="work_company_id" name="work_company_id" value="" />
                                    <input type="hidden" name="location" id="location" value="<?php echo $tab; ?>" />

                                        <?php if($tab == 'overview'){ ?>
                                            @include('dataentry.update_survivor')
                                        <?php } ?>

                                    <div class="tab-pane active" id="incidents" role="tabpanel">
                                        <?php if($tab == 'incidents'){ ?>
                                            @include('dataentry.update_incidents')
                                        <?php } ?>
                                    </div>
                                    <div class="tab-pane active" id="perpetrator" role="tabpanel">
                                        <?php if($tab == 'perpetrator'){ ?>
                                            @include('dataentry.update_perpetrator')
                                        <?php } ?>
                                    </div>

                                    <div class="tab-pane active" id="witness" role="tabpanel">
                                        <?php if($tab == 'witness'){ ?>
                                            @include('dataentry.update_witness')
                                        <?php } ?>
                                    </div>
                                    <div class="tab-pane active" id="action" role="tabpanel">
                                        <?php if($tab == 'action'){ ?>
                                            @include('dataentry.update_action')
                                        <?php } ?>
                                    </div>
                                    <div class="tab-pane active" id="status" role="tabpanel">
                                        <?php if($tab == 'status'){ ?>
                                            @include('dataentry.update_status')
                                        <?php } ?>
                                    </div>
                                    <hr>
                                    <div class="text-md-right testborder xhide pull pull-right">
                                        <a class="btn cancel gonowhere" type="button"> Cancel</a>
                                        <button class="btn btn-primary btn-green changesuccessurl savebutton savecontinue" type="submit" successurl="" pretext="Save and Continue">Save and Continue</button>
                                    </div>
                                </form>
                            </div>
                        </div>

                </div>
                <!-- Page-header end -->
            </div>
        </div>
    </div>
</div>

@push('scripts')
<script src="{{ asset('/assets/js/ngbvd-dataentry-final-fix.js') }}?v=20260604e"></script>
<script src="{{ asset('/assets/js/ngbvd-repeatable-sections.js') }}?v=20260604e"></script>
@endpush

@endsection
