<script setup>
import { useForm, Link } from '@inertiajs/vue3'

const form = useForm({
    name: '',
    email: '',
    password: '',
    password_confirmation: '',
})

const submit = () => {
    form.post('/register', {
        onFinish: () => form.reset('password', 'password_confirmation'),
    })
}
</script>

<template>
    <div class="auth-screen">
        <div class="scanlines" />
        <div class="terminal-frame">
            <div class="terminal-header">
                <span class="header-dot red" />
                <span class="header-dot yellow" />
                <span class="header-dot green" />
                <span class="header-title">AUTH.SYS v2.0</span>
            </div>

            <div class="terminal-body">
                <div class="prompt-line">
                    <span class="prompt-symbol">&gt;</span>
                    <span class="prompt-text">NEW USER REGISTRATION</span>
                    <span class="cursor" />
                </div>

                <h1 class="page-title">REGISTER</h1>

                <div class="divider">
                    <span>━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</span>
                </div>

                <form @submit.prevent="submit" class="auth-form">
                    <div class="field-group">
                        <label class="field-label" for="name">
                            <span class="label-prefix">[01]</span> DISPLAY_NAME:
                        </label>
                        <input
                            id="name"
                            v-model="form.name"
                            type="text"
                            class="field-input"
                            :class="{ 'field-error': form.errors.name }"
                            autocomplete="name"
                            placeholder="Voornaam Achternaam"
                            autofocus
                        />
                        <p v-if="form.errors.name" class="error-msg">
                            <span class="error-prefix">ERR:</span> {{ form.errors.name }}
                        </p>
                    </div>

                    <div class="field-group">
                        <label class="field-label" for="email">
                            <span class="label-prefix">[02]</span> EMAIL_ADDRESS:
                        </label>
                        <input
                            id="email"
                            v-model="form.email"
                            type="email"
                            class="field-input"
                            :class="{ 'field-error': form.errors.email }"
                            autocomplete="username"
                            placeholder="user@domain.nl"
                        />
                        <p v-if="form.errors.email" class="error-msg">
                            <span class="error-prefix">ERR:</span> {{ form.errors.email }}
                        </p>
                    </div>

                    <div class="field-group">
                        <label class="field-label" for="password">
                            <span class="label-prefix">[03]</span> PASSWORD:
                        </label>
                        <input
                            id="password"
                            v-model="form.password"
                            type="password"
                            class="field-input"
                            :class="{ 'field-error': form.errors.password }"
                            autocomplete="new-password"
                            placeholder="••••••••••••"
                        />
                        <p v-if="form.errors.password" class="error-msg">
                            <span class="error-prefix">ERR:</span> {{ form.errors.password }}
                        </p>
                    </div>

                    <div class="field-group">
                        <label class="field-label" for="password_confirmation">
                            <span class="label-prefix">[04]</span> CONFIRM_PASSWORD:
                        </label>
                        <input
                            id="password_confirmation"
                            v-model="form.password_confirmation"
                            type="password"
                            class="field-input"
                            :class="{ 'field-error': form.errors.password_confirmation }"
                            autocomplete="new-password"
                            placeholder="••••••••••••"
                        />
                        <p v-if="form.errors.password_confirmation" class="error-msg">
                            <span class="error-prefix">ERR:</span> {{ form.errors.password_confirmation }}
                        </p>
                    </div>

                    <button
                        type="submit"
                        class="submit-btn"
                        :disabled="form.processing"
                    >
                        <span v-if="form.processing">CREATING ACCOUNT...</span>
                        <span v-else>&gt;&gt; CREATE ACCOUNT</span>
                    </button>
                </form>

                <div class="divider">
                    <span>━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</span>
                </div>

                <div class="links">
                    <span class="links-text">ALREADY REGISTERED?</span>
                    <span class="link-separator"> // </span>
                    <Link href="/login" class="auth-link">
                        LOGIN HERE
                    </Link>
                </div>
            </div>
        </div>
    </div>
</template>

<style scoped>
.auth-screen {
    width: 100vw;
    height: 100vh;
    background: #1a1a2e;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.scanlines {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.08) 2px,
        rgba(0, 0, 0, 0.08) 4px
    );
    pointer-events: none;
    z-index: 1;
}

.terminal-frame {
    position: relative;
    z-index: 2;
    width: 480px;
    background: #0d0d1a;
    border: 2px solid #00d2ff;
    box-shadow:
        0 0 40px rgba(0, 210, 255, 0.25),
        inset 0 0 40px rgba(0, 210, 255, 0.03);
}

.terminal-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(0, 210, 255, 0.08);
    border-bottom: 1px solid rgba(0, 210, 255, 0.3);
}

.header-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: block;
}

.header-dot.red    { background: #e94560; box-shadow: 0 0 6px #e94560; }
.header-dot.yellow { background: #f5a623; box-shadow: 0 0 6px #f5a623; }
.header-dot.green  { background: #00ff88; box-shadow: 0 0 6px #00ff88; }

.header-title {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    color: #8892b0;
    margin-left: auto;
    letter-spacing: 2px;
}

.terminal-body {
    padding: 28px 40px 32px;
}

.prompt-line {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
}

.prompt-symbol {
    font-family: 'VT323', monospace;
    font-size: 20px;
    color: #00ff88;
}

.prompt-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    color: #8892b0;
    letter-spacing: 2px;
}

.cursor {
    display: inline-block;
    width: 10px;
    height: 16px;
    background: #00d2ff;
    animation: blink 1s step-end infinite;
    margin-left: 4px;
}

@keyframes blink {
    50% { opacity: 0; }
}

.page-title {
    font-family: 'Press Start 2P', monospace;
    font-size: 20px;
    color: #00d2ff;
    text-shadow: 0 0 30px rgba(0, 210, 255, 0.5);
    letter-spacing: 4px;
    margin: 0 0 16px 0;
}

.divider {
    font-family: 'VT323', monospace;
    font-size: 16px;
    color: rgba(0, 210, 255, 0.3);
    margin: 16px 0;
    overflow: hidden;
}

.auth-form {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-label {
    font-family: 'VT323', monospace;
    font-size: 18px;
    color: #8892b0;
    letter-spacing: 1px;
}

.label-prefix {
    color: #00d2ff;
    margin-right: 4px;
}

.field-input {
    background: rgba(0, 210, 255, 0.04);
    border: 1px solid rgba(0, 210, 255, 0.4);
    color: #e8e8e8;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 14px;
    padding: 10px 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
    box-sizing: border-box;
}

.field-input::placeholder {
    color: rgba(136, 146, 176, 0.4);
}

.field-input:focus {
    border-color: #00d2ff;
    box-shadow: 0 0 12px rgba(0, 210, 255, 0.2);
}

.field-input.field-error {
    border-color: #e94560;
    box-shadow: 0 0 8px rgba(233, 69, 96, 0.2);
}

.error-msg {
    font-family: 'VT323', monospace;
    font-size: 16px;
    color: #e94560;
    margin: 0;
}

.error-prefix {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: bold;
    margin-right: 4px;
}

.submit-btn {
    margin-top: 8px;
    padding: 14px 24px;
    background: rgba(0, 210, 255, 0.08);
    border: 2px solid #00d2ff;
    color: #00d2ff;
    font-family: 'Press Start 2P', monospace;
    font-size: 11px;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    width: 100%;
}

.submit-btn:hover:not(:disabled) {
    background: rgba(0, 210, 255, 0.18);
    box-shadow: 0 0 24px rgba(0, 210, 255, 0.35);
    transform: translateY(-1px);
}

.submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.links {
    text-align: center;
    font-family: 'VT323', monospace;
    font-size: 18px;
}

.links-text {
    color: #8892b0;
    letter-spacing: 1px;
}

.auth-link {
    color: #8892b0;
    text-decoration: none;
    letter-spacing: 1px;
    transition: color 0.2s;
}

.auth-link:hover {
    color: #00d2ff;
    text-shadow: 0 0 8px rgba(0, 210, 255, 0.4);
}

.link-separator {
    color: rgba(0, 210, 255, 0.3);
    margin: 0 4px;
}
</style>
