<script setup>
import { computed, onMounted, onUnmounted, watch } from 'vue';
import { aboutInPractice } from '@/lang/aboutInPractice';

const props = defineProps({
    open: { type: Boolean, default: false },
    locale: { type: String, default: 'en' },
});

const emit = defineEmits(['close']);

const copy = computed(() =>
    props.locale === 'ar' ? aboutInPractice.ar : aboutInPractice.en
);

function close() {
    emit('close');
}

function onKeydown(e) {
    if (e.key === 'Escape' && props.open) {
        close();
    }
}

watch(
    () => props.open,
    (isOpen) => {
        document.body.style.overflow = isOpen ? 'hidden' : '';
    },
);

onMounted(() => {
    window.addEventListener('keydown', onKeydown);
});

onUnmounted(() => {
    window.removeEventListener('keydown', onKeydown);
    document.body.style.overflow = '';
});
</script>

<template>
    <Teleport to="body">
        <Transition name="ip-about-fade">
            <div
                v-if="open"
                class="ip-about"
                role="dialog"
                aria-modal="true"
                :aria-label="copy.title"
                @click.self="close"
            >
                <div class="ip-about__bg">
                    <div class="ip-about__bg-overlay" />
                </div>

                <div class="ip-about__panel">
                    <button
                        type="button"
                        class="ip-about__close"
                        :aria-label="copy.close"
                        @click="close"
                    >
                        <i class="ti ti-x" aria-hidden="true" />
                    </button>

                    <div class="ip-about__scroll">
                        <p class="ip-about__tag">{{ copy.tagline }}</p>
                        <h2 class="ip-about__title">{{ copy.title }}</h2>
                        <p class="ip-about__intro">{{ copy.intro }}</p>

                        <section class="ip-about__section">
                            <h3 class="ip-about__h3">{{ copy.missionTitle }}</h3>
                            <p class="ip-about__p">{{ copy.mission }}</p>
                        </section>

                        <section class="ip-about__section">
                            <h3 class="ip-about__h3">{{ copy.pillarsTitle }}</h3>
                            <div class="ip-about__pillars">
                                <article class="ip-about__pillar">
                                    <span class="ip-about__pillar-label">{{ copy.pillarLearnTitle }}</span>
                                    <p>{{ copy.pillarLearn }}</p>
                                </article>
                                <article class="ip-about__pillar">
                                    <span class="ip-about__pillar-label">{{ copy.pillarConnectTitle }}</span>
                                    <p>{{ copy.pillarConnect }}</p>
                                </article>
                                <article class="ip-about__pillar">
                                    <span class="ip-about__pillar-label">{{ copy.pillarEarnTitle }}</span>
                                    <p>{{ copy.pillarEarn }}</p>
                                </article>
                            </div>
                        </section>

                        <section class="ip-about__section">
                            <h3 class="ip-about__h3">{{ copy.featuresTitle }}</h3>
                            <ul class="ip-about__features">
                                <li v-for="(f, i) in copy.features" :key="i">
                                    <strong>{{ f.name }}</strong>
                                    <span>{{ f.desc }}</span>
                                </li>
                            </ul>
                        </section>

                        <section class="ip-about__section">
                            <h3 class="ip-about__h3">{{ copy.whyTitle }}</h3>
                            <ul class="ip-about__why">
                                <li v-for="(item, i) in copy.why" :key="i">{{ item }}</li>
                            </ul>
                        </section>

                        <p class="ip-about__cta">{{ copy.cta }}</p>
                    </div>
                </div>
            </div>
        </Transition>
    </Teleport>
</template>

<style scoped>
.ip-about {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
        max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.ip-about__bg {
    position: absolute;
    inset: 0;
    background-image: url('/images/login-bg.jpg');
    background-size: cover;
    background-position: center;
    background-color: #0f2044;
}

.ip-about__bg-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        160deg,
        rgba(15, 32, 68, 0.94) 0%,
        rgba(15, 32, 68, 0.88) 45%,
        rgba(15, 32, 68, 0.92) 100%
    );
}

.ip-about__panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 640px;
    max-height: min(90vh, 820px);
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(15, 32, 68, 0.55);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

.ip-about__close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.15s ease;
}

[dir='rtl'] .ip-about__close {
    right: auto;
    left: 12px;
}

.ip-about__close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.ip-about__scroll {
    overflow-y: auto;
    padding: 28px 24px 24px;
    -webkit-overflow-scrolling: touch;
}

[dir='rtl'] .ip-about__scroll {
    text-align: right;
}

.ip-about__tag {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #1d9e75;
    margin: 0 0 8px;
}

.ip-about__title {
    font-size: 1.5rem;
    font-weight: 800;
    color: #fff;
    line-height: 1.2;
    margin: 0 0 14px;
    letter-spacing: -0.02em;
    padding-inline-end: 40px;
}

.ip-about__intro {
    font-size: 0.9rem;
    line-height: 1.65;
    color: rgba(255, 255, 255, 0.82);
    margin: 0 0 20px;
}

.ip-about__section {
    margin-bottom: 20px;
}

.ip-about__h3 {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #1d9e75;
    margin: 0 0 10px;
}

.ip-about__p {
    font-size: 0.875rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.78);
    margin: 0;
}

.ip-about__pillars {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ip-about__pillar {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
}

.ip-about__pillar p {
    margin: 6px 0 0;
    font-size: 0.8125rem;
    line-height: 1.55;
    color: rgba(255, 255, 255, 0.72);
}

.ip-about__pillar-label {
    font-size: 0.8125rem;
    font-weight: 700;
    color: #fff;
}

.ip-about__features {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ip-about__features li {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ip-about__features li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.ip-about__features strong {
    font-size: 0.8125rem;
    color: #fff;
}

.ip-about__features span {
    font-size: 0.8125rem;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.68);
}

.ip-about__why {
    margin: 0;
    padding: 0 0 0 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

[dir='rtl'] .ip-about__why {
    padding: 0 18px 0 0;
}

.ip-about__why li {
    font-size: 0.8125rem;
    line-height: 1.55;
    color: rgba(255, 255, 255, 0.75);
}

.ip-about__cta {
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.55;
    color: rgba(255, 255, 255, 0.9);
    margin: 8px 0 0;
    padding: 14px;
    border-radius: 10px;
    background: rgba(29, 158, 117, 0.15);
    border: 1px solid rgba(29, 158, 117, 0.35);
}

.ip-about-fade-enter-active,
.ip-about-fade-leave-active {
    transition: opacity 0.25s ease;
}

.ip-about-fade-enter-active .ip-about__panel,
.ip-about-fade-leave-active .ip-about__panel {
    transition: transform 0.28s cubic-bezier(0.34, 1.2, 0.64, 1), opacity 0.25s ease;
}

.ip-about-fade-enter-from,
.ip-about-fade-leave-to {
    opacity: 0;
}

.ip-about-fade-enter-from .ip-about__panel,
.ip-about-fade-leave-to .ip-about__panel {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
}

@media (min-width: 768px) {
    .ip-about__panel {
        max-width: 720px;
    }

    .ip-about__title {
        font-size: 1.75rem;
    }
}
</style>
