{% extends "templates/base.html" %}
{% block head_include %}
<meta name="description" content="{{ member.full_name }}" />
{% endblock %}


{% block content %}
{% set read_only = member.name != frappe.session.user %}
{% set user = member.name %}
{% set courses_created = get_authored_courses(member.name, True) %}
{% set certificates = get_certificates(user) %}

<div class="common-page-style profile-page">
    {{ ProfileBanner(member) }}
    <div class="profile-page-body">
        <div class="container">

            <ul class="nav lms-nav" id="courses-tab">

                <li class="nav-item">
                    <a class="nav-link active" data-toggle="tab" href="#profile">
                        {{ _("Profile") }}
                    </a>
                </li>

                {% if not read_only %}
                <li class="nav-item">
                    <a class="nav-link" data-toggle="tab" href="#courses-enrolled">
                        {{ _("Courses Enrolled") }}
                    </a>
                </li>
                {% endif %}

                {% if courses_created | length %}
                <li class="nav-item">
                    <a class="nav-link" data-toggle="tab" href="#courses-created">
                        {{ _("Courses Created") }}
                    </a>
                </li>
                {% endif %}

                {% if certificates | length %}
                <li class="nav-item">
                    <a class="nav-link" data-toggle="tab" href="#certificates">
                        {{ _("Certificates") }}
                    </a>
                </li>
                {% endif %}

                {% if not read_only %}
                <li class="nav-item">
                    <a class="nav-link" data-toggle="tab" href="#notifications">{{ _("Notifications") }}
                    </a>
                </li>
                {% endif %}

                {% if has_course_moderator_role() %}
                <li class="nav-item">
                    <a class="nav-link" data-toggle="tab" href="#settings">
                        {{ _("Settings") }}
                    </a>
                </li>
                {% endif %}

            </ul>

            <div class="border-bottom mb-4"></div>

            <div class="tab-content">
                <div class="tab-pane active" id="profile" role="tabpanel" aria-labelledby="profile">
                    <div class="common-card-style column-card mt-5">
                        {{ About(member) }}
                        {{ EducationDetails(member) }}
                        {{ WorkDetails(member) }}
                        {{ ExternalCertification(member) }}
                        {{ Contact(member) }}
                        {{ Skills(member) }}
                        {{ CareerPreference(member) }}
                        {{ ProfileTabs(profile_tabs) }}
                    </div>
                </div>

                {% if not read_only %}
                <div class="tab-pane fade" id="courses-enrolled" role="tabpanel" aria-labelledby="courses-enrolled">
                    {% include "lms/lms/web_template/courses_enrolled/courses_enrolled.html" %}
                </div>
                {% endif %}

                {% if courses_created | length %}
                {% set only_published = True %}
                <div class="tab-pane fade" id="courses-created" role="tabpanel" aria-labelledby="courses-created">
                    {% include "lms/templates/courses_created.html" %}
                </div>
                {% endif %}

                {% if certificates | length %}
                <div class="tab-pane fade" id="certificates" role="tabpanel" aria-labelledby="certificates">
                    {% include "lms/templates/certificates_section.html" %}
                </div>
                {% endif %}

                {% if not read_only %}
                <div class="tab-pane" id="notifications" role="tabpanel" aria-labelledby="notifications">
                    {% include "lms/templates/notifications.html" %}
                </div>
                {% endif %}

                <div class="tab-pane fade" id="settings" role="tabpanel" aria-labelledby="settings">
                    {{ RoleSettings(member) }}
                </div>

            </div>
        </div>
    </div>

</div>
{% endblock %}


<!-- Banner -->
{% macro ProfileBanner(member) %}
{% set cover_image = member.cover_image if member.cover_image else "/assets/lms/images/profile-banner.png" %}
{% set enrollment = get_course_membership(member.name, member_type="Student") | length %}
{% set enrollment_suffix = _("Courses") if enrollment > 1 else _("Course") %}

<div class="container">
    <div class="profile-banner" style="background-image: url({{ cover_image | urlencode }})">
        <div class="profile-avatar">
            {{ widgets.Avatar(member=member, avatar_class="avatar-square") }}
        </div>
    </div>

    <div class="profile-info">
        <div class="profile-name-section">
            <div class="profile-name" data-name="{{ member.name }}"> {{ member.full_name }} </div>

            {% if courses_created | length %}
            <div class="creator-badge"> {{ _("Creator") }} </div>
            {% endif %}

            {% if member.looking_for_job %}
            <div class="creator-badge"> {{ _("Open Network") }} </div>
            {% endif %}

            {% if frappe.session.user == member.email %}
            <div class="ml-auto mt-1">
                <a class="btn btn-secondary btn-sm" href="/courses"> {{ _("Course List") }} </a>
                <a class="btn btn-secondary btn-sm ml-2" href="/edit-profile/{{ member.email }}/edit"> {{ _("Edit Profile") }} </a>
            </div>
            {% endif %}
        </div>

        <div class="profile-meta">
            {% if member.headline %}
            <div class="course-meta mr-3"> {{ member.headline }} </div>
            {% endif %}

            {% if enrollment %}
            <div class="course-meta">
                <img src="/assets/lms/icons/book_plain.svg">
                {{ enrollment }} {{ enrollment_suffix }} {{ _("taken") }}
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endmacro %}


<!-- Courses Mentored -->
{% macro CoursesMentored(member, read_only) %}
{% if member.get_mentored_courses() | length %}
<div class="profile-courses">
    <div class="course-home-headings"> {{ _("Courses Mentored") }} </div>
    <div class="cards-parent">
        {% for course in member.get_mentored_courses() %}
        {{ widgets.CourseCard(course=course, read_only=read_only) }}
        {% endfor %}
    </div>
</div>
{% endif %}
{% endmacro %}


<!-- Profile Tabs Extension -->
{% macro ProfileTabs(profile_tabs) %}
<div>
    {% for tab in profile_tabs %}
    {% set slug = title.lower().replace(" ", "-") %}
    <div class="tab-content">
        <div class="tab-pane fade py-4 show active" role="tabpanel" id="slug">
            {{ tab.render() }}
        </div>
    </div>
    {% endfor %}
</div>
{% endmacro %}


<!-- Role Settings -->
{% macro RoleSettings(member) %}
    {% if has_course_moderator_role() %}
        <div class="">
            <div class="common-card-style column-card">
                <div class="course-home-headings"> {{ _("Role Settings") }} </div>
                <div class="medium">
                    <label class="role">
                        <input type="checkbox" id="instructor" data-role="Instructor"
                        {% if has_course_instructor_role(member.name) %} checked {% endif %}>
                        {{ _("Instructor") }}
                    </label>
                    <label class="role">
                        <input type="checkbox" id="moderator" data-role="Moderator"
                            {% if has_course_moderator_role(member.name) %} checked {% endif %}>
                        {{ _("Moderator") }}
                    </label>
                </div>
            </div>
        </div>
    {% endif %}
{% endmacro %}


<!-- About Section -->
{% macro About(member) %}
    <div class="course-home-headings"> {{ _("About") }} </div>
    <div class="description">
        {% if member.bio  %}
            {{ member.bio }}
        {% else %}
            {{ _("Hey, my name is ") }} {{ member.full_name }}
        {% endif %}
    </div>
{% endmacro %}


<!-- Work Preference -->
{% macro WorkPreference(member) %}
    <div class="course-home-headings mt-10"> {{ _("Work Preference") }} </div>
    <div> {{ member.attire }} </div>
    <div> {{ member.collaboration }} </div>
    <div> {{ member.role }} </div>
    <div> {{ member.location_preference }} </div>
    <div> {{ member.time }} </div>
    <div> {{ member.company_type }} </div>
{% endmacro %}


<!-- Career Preference -->
{% macro CareerPreference(member) %}
    {% if member.preferred_functions or member.preferred_industries or member.preferred_location or member.dream_companies %}
    <div class="course-home-headings mt-10"> {{ _("Career Preference") }} </div>
    <div class="profile-column-grid">

        {% if member.preferred_functions | length %}
        <div>
            <b>{{ _("Preferred Functions:") }}</b>
            {% for function in member.preferred_functions %}
            <div class="description">{{ function.function }}</div>
            {% endfor %}
        </div>
        {% endif %}

        {% if member.preferred_industries | length %}
        <div>
            <b>{{ _("Preferred Industries:") }}</b>
            {% for industry in member.preferred_industries %}
            <div class="description">{{ industry.industry }}</div>
            {% endfor %}
        </div>
        {% endif %}

        {% if member.preferred_location %}
        <div>
            <b> {{ _("Preferred Locations:") }} </b>
            <div class="description"> {{ member.preferred_location }} </div>
        </div>
        {% endif %}

        {% if member.dream_companies %}
        <div>
            <b> {{ _("Dream Companies:") }} </b>
            <div class="description"> {{ member.dream_companies }} </div>
        </div>
        {% endif %}

    </div>
    {% endif %}
{% endmacro %}


<!-- Contact Section -->
{% macro Contact(member) %}
    {% if member.linkedin or member.medium or member.github %}
    <div class="course-home-headings mt-10"> {{ _("Contact") }} </div>
    <div class="profile-column-grid">
    {% if member.linkedin %}
    {% set linkedin = member.linkedin[:-1] if member.linkedin[-1] == "/" else member.linkedin %}
    <a class="button-links description" href="{{ member.linkedin }}">
        <img src="/assets/lms/icons/linkedin.svg"> {{ linkedin.split("/")[-1] }}
    </a>
    {% endif %}

    {% if member.medium %}
    <a class="button-links description" href="{{ member.medium}}">
        <img src="/assets/lms/icons/medium.svg"> {{ member.medium.split("/")[-1] }}
    </a>
    {% endif %}

    {% if member.github %}
    <a class="button-links description" href="{{ member.github }}">
        <img src="/assets/lms/icons/github.svg"> {{ member.github.split("/")[-1] }}
    </a>
    {% endif %}

    </div>
    {% endif %}
{% endmacro %}


<!-- Skills -->
{% macro Skills(member) %}
    {% if member.skill | length %}
    <div class="course-home-headings mt-10"> {{ _("Skills")}} </div>
    <div class="profile-column-grid">
        {% for skill in member.skill %}
        <div class="description"> {{ skill.skill_name }} </div>
        {% endfor %}
    </div>
    {% endif %}
{% endmacro %}


<!-- Education Details -->
{% macro EducationDetails(member) %}
    {% if member.education %}
    <div class="course-home-headings mt-10"> {{ _("Education") }} </div>
    <div class="profile-grid-card">
        {% for edu in member.education %}
        <div class="column-card-row">
            <div class="bold-title"> {{ edu.institution_name }} </div>
            <div class="profile-item"> {{ edu.degree_type }} <span></span> {{ edu.major }}
                {% if not member.hide_private %}
                <!-- {% if edu.grade_type %} {{ edu.grade_type }}  {% endif %} -->
                {% if edu.grade %} <span></span> {{ edu.grade }}  {% endif %}
                {% endif %}
            </div>

            <div class="description">
                {% if edu.start_date %}
                {{ frappe.utils.format_date(edu.start_date, "MMM YYYY") }} -
                {% endif %}
                {{ frappe.utils.format_date(edu.end_date, "MMM YYYY") }}
            </div>
            <div class="description"> {{ edu.location }} </div>
        </div>
        {% endfor %}
    </div>
    {% endif %}
{% endmacro %}


<!-- Work Details -->
{% macro WorkDetails(member) %}
    {% set work_details = member.work_experience + member.internship %}

    {% if work_details | length %}
    <div class="course-home-headings mt-10"> {{ _("Work Experience") }} </div>
    <div class="profile-grid-card">

        {% for work in work_details %}
        <div class="">
            <div class="bold-title"> {{ work.title }} </div>
            <div class="profile-item"> {{ work.company }} </div>
            <div class="description">
                {{ frappe.utils.format_date(work.from_date, "MMM YYYY") }} -
                {% if work.to_date %} {{ frappe.utils.format_date(work.to_date, "MMM YYYY") }}
                {% else %} Present {% endif %}
            </div>

            <div class="description"> {{ work.location }} </div>

            {% if work.description %}
            <div class="profile-item">
                {{ work.description }}
            </div>
            {% endif %}
        </div>
        {% endfor %}

    </div>
    {% endif %}
{% endmacro %}


<!-- Certifications -->
{% macro ExternalCertification(member) %}
    {% if member.certification %}
    <div class="course-home-headings mt-10"> {{ _("External Certification") }} </div>
    <div class="profile-grid-card">
        {% for cert in member.certification %}
        <div class="">

            <div class="bold-title"> {{ cert.certification_name }} </div>
            <div class="profile-item"> {{ cert.organization }} </div>

            <div class="description">
                {{ frappe.utils.format_date(cert.issue_date, "MMM YYYY") }}
                {% if cert.expiration_date %}
                - {{ frappe.utils.format_date(cert.expiration_date, "MMM YYYY") }}
                {% endif %}
            </div>

            {% if cert.description %}
            <div class="profile-item">
                {{ cert.description }}
            </div>
            {% endif %}

        </div>
        {% endfor %}
    </div>
    {% endif %}
{% endmacro %}
