<?php

echo '<html>';
echo '<head>';
echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.debug.js"></script>';
echo '</head>';
echo '<body>';

//Inline styles (only for printing)
echo '<style type="text/css">
    body
    {
        font-family: "Arial", sans-serif;
        width:90%;
        margin: 0 auto;
    }
    .header-text
    {
        text-align:center;
        font-weight: bold;
        margin:0;
    }
    .outcome-text
    {
        text-align:left;
        font-weight: bold;
        margin:0;
    }
    h1.header-text
    {
      margin: 15px auto;
      width:75%;
      font-size: 25px;
    }

    table
    {
        border-collapse: collapse;
        border: 1px solid black;
        width: 100%;
        margin: 30px auto;
        font-size:1.5vw;
    }
    td, th
    {
        border: 1px solid black;
        padding: 5px;
    }

    .activity-name-row
    {
      background:black;
      color:white;
    }

    .activity-headers-row
    {
      background:lightgrey;
      font-weight:bold;
    }

    .report-info
    {
      margin:5px 0;
      font-size: 16px;
    }

    .criterion-field
    {
      text-align:left;
    }

    .score-field, .total, .percentage
    {
      text-align:center;
    }

    .header
    {
      margin: 30px 0;
    }

    .content
    {
      font-size: 12px;
    }

    .logo
    {
      position:absolute;
      right:0;
      top: 30px;
      width: 100px;
    }

    ul{
      list-style-type:none;
    }

    @media print{@page {size: landscape}}

    .outcome-header{
        text-align:left
    }
    hr{
        border-block-color: black
    }

    .course-title {
      text-align:center;
      font-weight:bold;
    }
</style>';

echo '<style type="text/css" media="print">
  @page { size: landscape; }
</style>';

?>
<div id="theEntireDoc">
    <img class="logo" src="{{ asset('images/logo_uprrp_bw.png') }}" alt="UPRRP Logo">

    <div class="header">
        <p class="header-text">University of Puerto Rico, Río Piedras Campus</p>
        <p class="header-text">Online Learning Assessment System</p>
        <p class="header-text">{{ $annualPlan->program->name }} Program Report</p>

        <h1 class="header-text">Academic Year {{ $annualPlan->annual_cycle->academic_year }} </h1>
    </div>

    @foreach ($annualPlan->outcomes as $outcome)
        @if ($outcome->student_performance != 'N/A')
            <h1 class="outcome-header">{{ $outcome->name }} <sub>(Semester
                    {{ Semester::find($outcome->semester_id)->code }})</sub></h1>
            <hr>
            <p class="outcome-text">Target to achieve the learning outcome: {{ $outcome->expected_outcome }} or more
                of
                the
                attempts</p>
            <p class="outcome-text">Expected percent of students achieving the target by learning outcome:
                {{ $outcome->expected_target }}%
            <p class="outcome-text">Results for {{ $outcome->name }}

                @if ($outcome->student_performance >= $outcome->expected_target)
                    <em style="color: green">{{ $outcome->student_performance }}% </em>
                @else
                    <em style="color: red">{{ $outcome->student_performance }}% </em>
                @endif

            </p>
            <hr>
            <ol type="I">
                <li>
                    <h2>Courses Assessment</h2>
                    <hr style="border-block-color: black">

                    <ol type="A">
                        @foreach ($outcome->annual_objectives as $objective)
                            <li>

                                <h2>{{ $objective->text }}: </h2>

                                @foreach ($objective->grouped_annual_course as $course_code)
                                    <h2 class="course-title">
                                        {{ $course_code->code }}-{{ $course_code->number }}
                                    </h2>
                                    <h2 class="outcome-text">Performance of Students by Learning Outcome Criteria</h2>
                                    <table class="table table-striped table-condensed">
                                        <thead>
                                            <tr>
                                                <th></th>
                                                <th>Criteria</th>

                                                <th>Number of Students Assessed</th>


                                                <th>Number of Students that Achieved the Target</th>
                                                <th>Percentage</th>

                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach ($course_code->assessed_paired_criteria as $index => $criterion)
                                                <tr>
                                                    <td>{{ $index + 1 }}.</td>
                                                    <td>
                                                        {{ $criterion->name }}

                                                        @if ($criterion->subcriteria)
                                                            <ul class="list-unstyled">
                                                                @foreach (json_decode($criterion->subcriteria) as $subcriterion)
                                                                    <li>{{ $subcriterion }}</li>
                                                                @endforeach
                                                            </ul>
                                                        @endif
                                                    </td>
                                                    <td>
                                                        {{ $criterion->criteria_attempted }}
                                                    </td>
                                                    <td>
                                                        {{ $criterion->criteria_achieved }}
                                                    </td>

                                                    <td>
                                                        {{ round(($criterion->criteria_achieved / $criterion->criteria_attempted) * 100, 2) }}%
                                                    </td>


                                                </tr>
                                            @endforeach

                                        </tbody>
                                    </table>
                                    @if (count($course_code->proposed_transformative_actions) > 0)
                                        <h2 class="outcome-text">Follow up on Course's Proposed Transformative Actions
                                        </h2>
                                        <table class="table table-striped table-condensed">
                                            <thead>
                                                <tr>
                                                    <th></th>
                                                    <th>Transformative Actions</th>

                                                    <th>Was it Implemented on Semester
                                                        {{ Semester::find($outcome->semester_id)->code }} ?</th>


                                                    <th>Was this transformative action helpful to achieve the learning
                                                        expectation?</th>
                                                    <th>Explain briefly about the implementation of this transformative
                                                        action
                                                        or why was it not implemented</th>

                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php Log::info(json_encode($course_code->proposed_transformative_actions)); ?>
                                                @foreach ($course_code->proposed_transformative_actions as $index => $ta)
                                                    <tr>
                                                        <td>{{ $index + 1 }}.</td>
                                                        <td>
                                                            <strong>{{ $ta->at_text }}: </strong>
                                                            {{ $ta->description }}


                                                        </td>
                                                        @if (!isset($ta->status))
                                                            <td>
                                                                Has not been followed up yet (Please follow up)
                                                            </td>
                                                            <td>
                                                                Has not been followed up yet (Please follow up)
                                                            </td>
                                                            <td>
                                                                Has not been followed up yet (Please follow up)
                                                            </td>
                                                        @else
                                                            <td>
                                                                @if ($ta->status->accomplished == 1)
                                                                    Yes
                                                                @else
                                                                    No
                                                                @endif
                                                            </td>
                                                            <td>
                                                                @if ($ta->status->accomplished == 1)
                                                                    @if ($ta->status->it_was_useful == 1)
                                                                        Yes
                                                                    @else
                                                                        No
                                                                    @endif
                                                                @else
                                                                    N/A
                                                                @endif

                                                            </td>

                                                            <td>

                                                                {{ $ta->status->comments }}
                                                            </td>
                                                        @endif


                                                    </tr>
                                                @endforeach

                                            </tbody>
                                        </table>
                                    @endif
                                    @if (count($course_code->future_transformative_actions) > 0)
                                        <h2 class="outcome-text">Future Transformative Actions for Course
                                        </h2>
                                        <table class="table table-striped table-condensed">
                                            <thead>
                                                <tr>
                                                    <th></th>
                                                    <th>Transformative Actions to be Implemented</th>

                                                    <th>Semesters where the Transformative Action will be Implemented
                                                    </th>




                                                </tr>
                                            </thead>
                                            <tbody>

                                                @foreach ($course_code->future_transformative_actions as $index => $ta)
                                                    <tr>
                                                        <td>{{ $index + 1 }}.</td>
                                                        <td>
                                                            <strong>{{ $ta->at_text }}: </strong>
                                                            {{ $ta->description }}


                                                        </td>
                                                        <td>
                                                            @foreach ($ta->future_semesters as $semester)
                                                                <p style="display:inline">{{ $semester->code }}, </p>
                                                            @endforeach
                                                        </td>


                                                    </tr>
                                                @endforeach

                                            </tbody>
                                        </table>
                                    @endif
                                    <hr>
                                @endforeach




                            </li>
                        @endforeach


                    </ol>


                </li>



                @if (count($outcome->program_transformative_actions) > 0)
                    <li>
                        <h2>Program Transformative Actions</h2>
                        <hr>

                        <table class="table table-striped table-condensed">
                            <thead>
                                <tr>
                                    <th></th>
                                    <th>Transformative Action</th>
                                    <th>Category</th>
                                    <th>Results</th>

                                    <th>Was this helpful to achieve the learning expectation?</th>
                                    <th>Explain briefly details about the implementation</th>

                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($outcome->program_transformative_actions as $index => $ta)
                                    <tr>
                                        <td>{{ $index + 1 }}.</td>
                                        <td>
                                            <strong>{{ $ta->at_text }}: </strong>{{ $ta->description }}


                                        </td>
                                        <td>
                                            {{ $ta->type_of_TA }}
                                        </td>

                                        @if (!isset($ta->status))
                                            <td>Has Not yet submitted</td>
                                            <td>Has Not Yet Submitted</td>
                                            <td>Has Not Yet Submitted</td>
                                        @else
                                            <td>
                                                {{ $ta->status->results }}
                                            </td>

                                            <td>
                                                @if ($ta->status->it_was_useful == 1)
                                                    Yes
                                                @else
                                                    No
                                                @endif
                                            </td>
                                            <td>
                                                {{ $ta->status->comments }}
                                            </td>
                                        @endif


                                    </tr>
                                @endforeach

                            </tbody>
                        </table>
                        <hr>
                    </li>
                @endif

                @if (count($outcome->comments) > 0)
                    <li>
                        <h2>Comments</h2>
                        <hr>
                        <table class='table table-striped table-condensed'>
                            <tbody>
                                @foreach ($outcome->comments as $index => $comment)
                                    <tr>
                                        <td>
                                            {{ $index + 1 }}.
                                        </td>
                                        <td>
                                            {{ $comment->comments }}
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>

                    </li>
                @endif
            </ol>
        @else
            <h1 class="outcome-header">{{ $outcome->name }} <sub>(Semester
                    {{ Semester::find($outcome->semester_id)->code }})</sub></h1>
            <hr>
            <p class="outcome-text">Target to achieve the learning outcome: {{ $outcome->expected_outcome }} or
                more of
                the
                attempts</p>
            <p class="outcome-text">Expected percent of students achieving the target by learning outcome:
                {{ $outcome->expected_target }}%
            <p class="outcome-text">Results for {{ $outcome->name }}


                <em style="color: red">{{ $outcome->student_performance }} </em>


            </p>
            <p class="outcome-text" style="color: red">No student has been assessed in this outcome</p>
            <hr>
        @endif
    @endforeach
</div>

{{-- @foreach ($outcome->program_transformative_actions as $trans)
                                <li>
                                    <h2><strong>{{ $trans->at_text }}: {{ $trans->description }}</strong></h2>

                                    @if (isset($trans->status))
                                        <p><strong>Results: </strong>{{ $trans->status->results }}</p>
                                        <p><strong>Was this helpful to achieve the learning expectation? </strong>
                                            @if ($trans->status->it_was_useful == 1)
                                                Yes
                                            @else
                                                No
                                            @endif
                                        </p>
                                        <p><strong>Explain briefly details about the implementation: </strong>
                                            {{ $trans->status->comments }}
                                        </p>
                                    @else
                                        <p><strong>Please submit the results </strong>
                                    @endif

                                </li>
                            @endforeach
                        </ol> --}}

<?php

echo '</body>';
echo '</html>';
?>

<script type="text/javascript">
    window.print();
</script>