@php
    use App\Models\Patient;
@endphp
@extends('capture.layoutv6')
@section('title', 'EndoINDEX')
@section('style')
    <style>
        .fs-30 {
            font-size: 30px;
            font-weight: 400;
        }

        .fs-19 {
            font-size: 19px;
        }

        .modal-lg,
        .modal-xl {
            --vz-modal-width: 812px;
        }

        .col-2-5 {
            width: 20.8333%;
        }

        .col-0-5 {
            flex: 0 0 4.16667%;
            max-width: 4.16667%;
        }

        .col-1-5 {
            width: 12.5%;
        }

        .bg-dark-primary {
            background-color: #192d4b !important;
        }
    </style>
    <meta name="csrf-token" content="{{ csrf_token() }}" />
    <link href="{{ url('public/css/patient/create.css') }}" rel="stylesheet" type="text/css" />
    <link href="{{ url('public/css/input/main.css') }}" rel="stylesheet" type="text/css" />

@endsection
@section('modal')
    <div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"
        id="mi-modal">
        <div class="modal-dialog modal-dialog-centered modal-lg">
            <div class="modal-content p-3">

                <div align="center">
                    <br>
                    <span class="modal-title text-color-index  fs-30 mb-2 " id="myModalLabel">HN :
                        <div id="patient_hn" class="d-inline"></div>
                    </span>
                    <span class="modal-title fw-normal mb-2" id="myModalLabel">
                        <div id="patient_name" class="text-color-index  fs-30 "></div>
                    </span>

                    <span class="text-danger fs-19">
                        This name has already been registered in the system.
                    </span>
                    <br>


                </div>
                <div class="modal-footer">
                    <div class="row mt-3" style="    width: 100%;">
                        <div class="col-6 text-end">
                            <button type="button" class="btn btn-danger" data-bs-dismiss="modal" style="width: 50%;">
                                <span class="text-modal">Cancel</span>
                            </button>
                        </div>
                        <div class="col-6">
                            <a id="opencase" type="button" class="btn btn-load btn-primary" href=""
                                style="width: 50%;"><span class="text-modal">Confirm</span></a>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
@endsection
@section('content')
@section('title-left')
    @php
        // dd($type);
        // $action_cap = @$action . '' == 'edit' ? 'EDIT PATIENT' : strtoupper('create new');
        $action_txt = @$action . '' == 'edit' ? 'Edit' : 'Create';
        $action_txt2 = @$action . '' == 'edit' ? 'EDIT' : 'REGISTRATION';
    @endphp
    <h4 class="mb-sm-0">{{ @$action_cap }}</h4>
@endsection

{{-- @section('title-right')
    <ol class="breadcrumb m-0">
        <li class="breadcrumb-item"><a href="javascript: void(0);">Operation </a></li>
        <li class="breadcrumb-item active text-gray">{{ @$action_txt }}</li>
    </ol>
@endsection --}}
{{-- <div class="col-12 cardcode" style="display: none">
                    <div class="card card-custom gutter-b">
                        <div class="card-body">
                            <label id="discharge_toggle">
                                <font size='4'><b>Page Detail</b></font>
                            </label>
                            <div class="row">
                                <div class="col-12">
                                    <a id="test123">PatientController -> Create</a>
                                    <br>
                                    Controller : <a
                                        href="{{ url("autoit?run=visualcode_open\\endo.exe&path=PatientController") }}">PatientController</a>
                                </div>
                                <div class="col-12">
                                    View : <a
                                        href="{{ url("autoit?run=visualcode_open\\endo.exe&path=endo/patient/create.blade.php") }}">endo/patient/create.blade.php</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="clearfix"></div>
                <form action="{{url('book/patient')}}" method="post" class="col-12">
                    @csrf
                    <input type="hidden" name="event" value="">
                    <div class="row">
                        <div class="col-lg-3">
                            <div class="card h-100">

                            </div>
                        </div>
                    </div>
                </form> --}}


<form id="patient_form" action="{{ url('patient') }}" method="post">
    @csrf
    <input type="hidden" name="event" value="patient_create">
    @isset($_GET['historytaking'])
        <input type="hidden" name="historytaking" value="true">
    @endisset



    <div class="row g-0 delete-h" id="step01" style="margin: 0;">

        <div class="col-3" style="padding:px; ">
            <div class="card">
                {{-- <div class="card-body bg-dark-primary h-60">
                    <div class="row">
                        <div class="col-12">
                            <a type="button" id="patient_test" class="btn btn-white btn-icon waves-effect waves-light "
                                data-toggle="tooltip" title="Create patient test">
                                <i class="ri-edit-2-fill ri-xl m-0"></i>
                            </a>
                        </div>
                        <div class="col-12">
                            <div class="col" align="center">
                                @if (@$patient->pic == '')
                                    <img src="{{ url('public/images/usericon1.jpg') }}" width="93" height="93"
                                        style="border-radius: 50%" alt="">
                                @else
                                    <img id="imgnew"
                                        src="{{ url("pic_patient/$patient->pic") }}?a={{ date('Y-m-dH:i:s') }}"
                                        width="183px" />
                                @endif
                            </div>
                        </div>
                        <div class="col-12 mt-5">
                            @if (count($errors) > 0)
                                <div class="alert alert-danger">
                                    <ul>
                                        @foreach ($errors->all() as $error)
                                            <li>{{ $error }}</li>
                                        @endforeach
                                    </ul>
                                </div>
                            @endif
                            @if (@$action . '' == 'edit')
                                <input type="hidden" name="event" value="edit_patient">
                            @endif
                            <input type="hidden" name="patient_id" value="{{ @$patient_id }}">
                            <input type="hidden" name="type" value="{{ @$type }}">
                            <input type="hidden" name="cid" value="{{ @$cid }}">
                            <input type="hidden" name="myHiddenField">
                            <div class="row">
                                <div class="col-12">
                                    <div class="form-group">
                                        <span class="col-form-label">
                                            <font size="2">Patient ID*</font>
                                        </span>
                                        <input type="text" name="hn" id="hn"
                                            class="form-control bg-white" value="{{ Patient::show_hn(@$patient->hn) }}"
                                            placeholder="HN" required
                                            @if (@$action . '' == 'edit') disabled @endif>
                                        <div id="show_lang_in_here"></div>
                                    </div>
                                    <div class="form-group mt-5">
                                        <span class="col-form-label">
                                            <font size="2">Admit ID</font>
                                        </span>
                                        @if (isset($patient->an))
                                            {{ Form::text('an', $patient->an, ['class' => 'form-control', 'readonly', 'autocomplete', 'bg-white' => 'off']) }}
                                        @else
                                            {{ Form::text('an', '', ['class' => 'form-control', 'autocomplete' => 'off']) }}
                                        @endif
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div> --}}
            </div>
        </div>
        <div class="col-lg-12 mt-1">
            <div class="card">
                <div class="card-body">
                    <div class="">
                        {{-- <h4 class="ms-3 mb-5 text-blue"> {{ @$action_txt2 }} FORM</h4> --}}
                        <h4 class="ms-3 mb-5 text-blue" style="color: #192D48;"> Registration Form</h4>
                    </div>

                    <div class="row m-0 cn">

                        <div class="col-3"><b class="text-blue h5 m-0">Procedure <span class="text-danger">*</span></b>
                            <select name="case_procedure" id="" class="form-select">
                                <option value="colonoscopy" selected>Colonoscopy</option>
                                <option value="EGD" >EGD</option>
                                <option value="ERCP">ERCP</option>
                                <option value="EUS">EUS</option>
                            </select>
                        </div>

<div class="col-4"></div>
                        <div class="col-3">
                            <h2>อัพโหลดไฟล์ Excel</h2>

                            @if (session('success'))
                                <div style="color: green;">{{ session('success') }}</div>
                            @endif

                            @if (session('error'))
                                <div style="color: red;">{{ session('error') }}</div>
                            @endif

                            <form id="uploadForm" action="{{ route('upload.import') }}" method="POST" enctype="multipart/form-data">
                                @csrf
                                <input type="file" name="file" accept=".xlsx, .xls">
                                <button type="submit">อัพโหลด</button>
                            </form>
                        </div>



                    </div>





                    <br><br>
                    <br>
                    <div class="" style="padding-bottom:13px;"></div>
                    {{-- <div class="row m-0 mt-2 pt-1">
                        <div class="col-2 align-self-center"><b class="text-blue h5 m-0">Allergy</b></div>
                        <div class="col-7">
                            @if (isset($patient->allergic))
                                {{ Form::text('allergic', $patient->allergic, ['class' => 'form-control bg-gray-input']) }}
                            @else
                                {{ Form::text('allergic', '', ['class' => 'form-control bg-gray-input']) }}
                            @endif
                        </div>

                    </div> --}}
                    {{-- <div class="row m-0 mt-1 text-muted">
                        <div class="col-2"></div>
                        <div class="col-3 text-gray">Allegy</div>

                    </div> --}}

                    <div class="form-row">
                        <div class="row">
                            <div class="col-auto">
                                @if (@$feature->citizencard)
                                    <button type="button" id="read_card"
                                        class="btn btn-danger btn-label waves-effect waves-light"
                                        onclick="read_idcard()">
                                        <i class="bx bx-id-card label-icon align-middle fs-16"></i> Read ID
                                        Card</button>
                                @endif
                            </div>
                            <div class="col"></div>
                            <div class="col-auto ">

                            </div>
                            <button id="warning_div" type="button" data-toast data-toast-text=""
                                data-toast-gravity="bottom" data-toast-position="right" data-toast-duration="3000"
                                data-toast-close="close" data-toast-className="danger" class="btn btn-light w-xs"
                                style="display:none">Bottom Right</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        @php
            $head = configTYPE('pdf', 'pdf_folder_head');
            $pathhispatient = $_SERVER['DOCUMENT_ROOT'] . "/config/views/his/$head/patient_get_detail.blade.php";
        @endphp
        @if (is_file($pathhispatient))
            @include("his.$head.patient_get_detail")
        @else
            @include('endo.patient.his.00000')
        @endif
    </div>



@endsection
@section('script')
<script>
$(document).ready(function() {
    $('#uploadForm').on('submit', function(e) {
        e.preventDefault();

        var formData = new FormData(this);

        $.ajax({
            url: $(this).attr('action'),
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            success: function(response) {
                // แสดงข้อความสำเร็จ
                alert('อัพโหลดสำเร็จ');
            },
            error: function(xhr) {
                // แสดงข้อความผิดพลาด
                alert('เกิดข้อผิดพลาดในการอัพโหลด');
            }
        });
    });
});
</script>
@endsection
