@extends('layouts.yellow')
@section('content')
<div class="container-lg">
    <div class="row mb-4">
        <div class="col-md-10 mx-auto">
            <div class="card shadow-sm border-0 rounded-lg overflow-hidden">
                <div class="card-header text-white py-4" style="background: linear-gradient(135deg, #4A90E2 0%, #2A4E6D 100%);">
                    <div class="d-flex justify-content-between align-items-center">
                        <h2 class="mb-0 font-weight-bold">
                            <i class="fa fa-file-medical-alt mr-2"></i> {{__("detail-patient.medicalReport")}}
                        </h2>
                        <a href="{{URL::route('/admin/view-medical-reports',['patientId'=>$patientId])}}" 
                            class="btn btn-light rounded-pill shadow-sm" style="transition: all 0.3s ease;">
                            <i class="fa fa-arrow-left mr-2"></i> {{__("com-form-history.backReturn")}}
                        </a>
                    </div>
                </div>
                
                <div class="card-body p-4">
                    <div class="clinic-identity p-3 mb-4 text-center border-bottom">
                        @php
                            $identity = \App\Helper\ClinicIdentityHelper::getActiveIdentity();
                        @endphp
                        
                        @if($identity && $identity->logo_path)
                            <img src="{{ asset('storage/' . $identity->logo_path) }}" 
                                alt="Logo {{ $identity->name }}" 
                                style="max-height: 100px; max-width: 300px;" class="mb-3">
                        @endif
                        
                        @if($identity)
                            <h3 class="text-color-4245A4 mb-1 font-weight-bold">{{ $identity->name }}</h3>
                            @if($identity->specialty)
                                <p class="mb-1 text-muted"><em>{{ $identity->specialty }}</em></p>
                            @endif
                            <p class="mb-1">{{ $identity->address }}</p>
                            
                            @if($identity->phone || $identity->email)
                                <p class="mb-3">
                                    @if($identity->phone) <i class="fa fa-phone-alt mr-1"></i> {{ $identity->phone }} @endif
                                    @if($identity->phone && $identity->email) | @endif
                                    @if($identity->email) <i class="fa fa-envelope mr-1"></i> {{ $identity->email }} @endif
                                </p>
                            @endif
                        @endif
                    </div>
                    
                    <div class="patient-info-container mb-4">
                        <div class="d-flex align-items-center">
                            <div class="patient-info-icon mr-3 d-flex align-items-center justify-content-center rounded-circle" 
                                style="width: 50px; height: 50px; background: #E3F2FD; color: #2A4E6D;">
                                <i class="fa fa-user-md fa-lg"></i>
                            </div>
                            <div>
                                <h5 class="text-color-4245A4 mb-1">{{__("detail-patient.patient")}}</h5>
                                <h4 class="font-weight-bold mb-0">{{$patientName}}</h4>
                            </div>
                            <div class="ml-auto">
                                <p class="mb-0 text-muted"><i class="fa fa-calendar mr-1"></i> {{ date('d/m/Y') }}</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="report-content mb-4">
                        <div class="form-group">
                            
                            <label for="specialities" class="font-weight-bold mb-2">
                                <i class="fa fa-clipboard-list mr-2"></i>{{__('detail-patient.specialitySelected')}}
                            </label>
                            
                            <input class="form-control border-0 shadow-none" type="text" name="specialities" id="specialities" value="{{$especiality}}" readonly>
                            <br>
                            <label for="description" class="font-weight-bold mb-2">
                                <i class="fa fa-clipboard-list mr-2"></i>{{__('detail-patient.descriptionMedicalReport')}}
                            </label>
                            <div class="border rounded-lg p-2" style="background-color: #fcfcfc;">
                                <textarea 
                                    readonly 
                                    class="form-control border-0 shadow-none" 
                                    placeholder="{{__('detail-patient.descriptionMedicalReport')}}" 
                                    id="description" 
                                    name="description" 
                                    rows="16"
                                    style="background-color: transparent; resize: none;"
                                >{{$description}}</textarea>
                            </div>
                        </div>
                    </div>
                    
                    @php
                        $report = App\Models\MedicalReport::find($id);
                        $doctor = $report ? $report->user()->first() : null;
                        $hasDoctorSignature = $doctor && $doctor->hasDigitalSignature();
                    @endphp

                    @if($hasDoctorSignature)
                    <div class="signature-container mb-4 text-center">
                        <div class="alert alert-success d-flex align-items-center" style="border-left: 4px solid #28a745; background-color: #f8f9fa; border-radius: 8px;">
                            <div class="alert-icon mr-3 d-flex align-items-center justify-content-center rounded-circle" 
                                style="width: 40px; height: 40px; min-width: 40px; background: rgba(40, 167, 69, 0.2);">
                                <i class="fas fa-check-circle text-success"></i>
                            </div>
                            <div class="text-left">
                                <h5 class="alert-heading mb-1">{{__('doctor.report.docSignature')}}</h5>
                                <p class="mb-0">{{__('doctor.report.signedBy', ['name' => $doctor->name])}}</p>
                            </div>
                            
                            @if($doctor && $doctor->signature_path)
                            <div class="ml-auto signature-image">
                                <img src="{{ asset('storage/signatures/' . $doctor->signature_path) }}" 
                                    alt="Firma digital" style="max-height: 60px; max-width: 150px;">
                            </div>
                            @endif
                        </div>
                    </div>
                    @endif
                    
                    <div class="text-center">
                        <a href="{{URL::route('/admin/download-medical-report',['id'=>$id])}}"
                            class="btn btn-success rounded-pill px-4 py-2" download 
                            style="background: linear-gradient(135deg, #28a745 0%, #218838 100%) !important; border: none; transition: all 0.3s ease;">
                            <i class="fa fa-download mr-2"></i>{{__("detail-patient.createMedicalReportAndDownload")}}
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .btn {
        transition: all 0.3s ease;
    }
    .btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.1) !important;
    }
    .card {
        transition: all 0.3s ease;
    }
    .card:hover {
        box-shadow: 0 5px 15px rgba(0,0,0,0.1) !important;
    }
    textarea:focus {
        box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1) !important;
    }
    .signature-image img {
        transition: all 0.3s ease;
    }
    .signature-image img:hover {
        transform: scale(1.05);
    }
</style>
@endsection