<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ prompt.title }} - Shared from PromptBin</title>
    
    <!-- Meta tags for social sharing -->
    <meta property="og:title" content="{{ prompt.title }}">
    <meta property="og:description" content="{{ prompt.description or 'A prompt shared from PromptBin' }}">
    <meta property="og:type" content="article">
    <meta property="og:site_name" content="PromptBin">
    
    <meta name="twitter:card" content="summary">
    <meta name="twitter:title" content="{{ prompt.title }}">
    <meta name="twitter:description" content="{{ prompt.description or 'A prompt shared from PromptBin' }}">
    
    <!-- Highlight.js for syntax highlighting -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
    
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
            line-height: 1.6;
            color: #333;
            background: #f8f9fa;
            min-height: 100vh;
        }
        
        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 2rem;
            background: white;
            min-height: 100vh;
            box-shadow: 0 0 20px rgba(0,0,0,0.1);
        }
        
        .header {
            text-align: center;
            margin-bottom: 2rem;
            padding-bottom: 1rem;
            border-bottom: 2px solid #2563eb;
        }
        
        .logo {
            font-size: 1.5rem;
            font-weight: bold;
            color: #2563eb;
            text-decoration: none;
            margin-bottom: 0.5rem;
            display: inline-block;
        }
        
        .share-badge {
            font-size: 0.875rem;
            color: #6b7280;
            background: #f3f4f6;
            padding: 0.25rem 0.75rem;
            border-radius: 1rem;
            display: inline-block;
        }
        
        .prompt-header {
            margin-bottom: 2rem;
        }
        
        .prompt-title {
            font-size: 2rem;
            font-weight: bold;
            color: #111827;
            margin-bottom: 0.5rem;
        }
        
        .prompt-meta {
            display: flex;
            flex-wrap: wrap;
            gap: 1rem;
            margin-bottom: 1rem;
            font-size: 0.875rem;
            color: #6b7280;
        }
        
        .category-badge {
            padding: 0.25rem 0.5rem;
            border-radius: 0.25rem;
            font-size: 0.75rem;
            font-weight: 500;
            text-transform: capitalize;
        }
        
        .category-badge.coding {
            background: #dbeafe;
            color: #1e40af;
        }
        
        .category-badge.writing {
            background: #dcfce7;
            color: #166534;
        }
        
        .category-badge.analysis {
            background: #fef3c7;
            color: #92400e;
        }
        
        .prompt-description {
            font-size: 1.125rem;
            color: #4b5563;
            line-height: 1.6;
            margin-bottom: 1rem;
        }
        
        .prompt-tags {
            display: flex;
            flex-wrap: wrap;
            gap: 0.5rem;
            margin-bottom: 1.5rem;
        }
        
        .tag {
            padding: 0.25rem 0.5rem;
            background: #f3f4f6;
            color: #374151;
            font-size: 0.75rem;
            border-radius: 0.25rem;
        }
        
        .prompt-content {
            background: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: 0.5rem;
            margin-bottom: 2rem;
            position: relative;
        }
        
        .content-header {
            padding: 1rem;
            border-bottom: 1px solid #e5e7eb;
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: white;
            border-radius: 0.5rem 0.5rem 0 0;
        }
        
        .content-header h3 {
            margin: 0;
            color: #374151;
            font-size: 1rem;
        }
        
        .copy-button {
            padding: 0.5rem 1rem;
            background: #2563eb;
            color: white;
            border: none;
            border-radius: 0.25rem;
            font-size: 0.875rem;
            cursor: pointer;
            transition: background 0.15s ease;
        }
        
        .copy-button:hover {
            background: #1d4ed8;
        }
        
        .content-body {
            padding: 1.5rem;
            background: white;
            border-radius: 0 0 0.5rem 0.5rem;
        }
        
        .prompt-text {
            font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
            font-size: 0.875rem;
            line-height: 1.6;
            white-space: pre-wrap;
            word-wrap: break-word;
            color: #1f2937;
        }
        
        .template-var {
            background-color: #fef3c7;
            color: #92400e;
            padding: 0.125rem 0.25rem;
            border-radius: 0.25rem;
            font-weight: 500;
        }
        
        .share-info {
            background: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: 0.5rem;
            padding: 1rem;
            margin-bottom: 2rem;
            font-size: 0.875rem;
            color: #6b7280;
        }
        
        .footer {
            text-align: center;
            padding-top: 2rem;
            border-top: 1px solid #e5e7eb;
            color: #6b7280;
            font-size: 0.875rem;
        }
        
        .footer a {
            color: #2563eb;
            text-decoration: none;
        }
        
        .footer a:hover {
            text-decoration: underline;
        }
        
        .stats {
            display: flex;
            gap: 1rem;
            font-size: 0.75rem;
        }
        
        /* Mobile responsive */
        @media (max-width: 640px) {
            .container {
                padding: 1rem;
            }
            
            .prompt-title {
                font-size: 1.5rem;
            }
            
            .prompt-meta {
                flex-direction: column;
                gap: 0.5rem;
            }
            
            .stats {
                flex-direction: column;
                gap: 0.25rem;
            }
        }
        
        /* Toast notification styles */
        .toast {
            position: fixed;
            top: 20px;
            right: 20px;
            background: #2563eb;
            color: white;
            padding: 1rem;
            border-radius: 0.5rem;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            z-index: 1000;
            opacity: 0;
            transform: translateY(-20px);
            transition: all 0.3s ease;
        }
        
        .toast.show {
            opacity: 1;
            transform: translateY(0);
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <a href="/" class="logo">PromptBin</a>
            <div class="share-badge">📤 Shared Prompt</div>
        </div>
        
        <div class="prompt-header">
            <h1 class="prompt-title">{{ prompt.title }}</h1>
            
            <div class="prompt-meta">
                <span class="category-badge {{ prompt.category }}">{{ prompt.category.title() }}</span>
                <span>Created: {{ prompt.created_at[:10] }}</span>
                {% if share_info and share_info.access_count > 1 %}
                <span>{{ share_info.access_count }} views</span>
                {% endif %}
                <div class="stats">
                    <span>{{ prompt.content.split()|length }} words</span>
                    <span>{{ (prompt.content.split()|length * 1.3)|round|int }} tokens</span>
                    {% set template_vars = prompt.content|regex_findall('\{\{[^}]+\}\}')|length %}
                    {% if template_vars > 0 %}
                    <span>{{ template_vars }} variable{{ 's' if template_vars != 1 else '' }}</span>
                    {% endif %}
                </div>
            </div>
            
            {% if prompt.description %}
            <p class="prompt-description">{{ prompt.description }}</p>
            {% endif %}
            
            {% if prompt.tags %}
            <div class="prompt-tags">
                {% for tag in prompt.tags %}
                <span class="tag">{{ tag }}</span>
                {% endfor %}
            </div>
            {% endif %}
        </div>
        
        <div class="prompt-content">
            <div class="content-header">
                <h3>Prompt Content</h3>
                <button class="copy-button" onclick="copyToClipboard()">📋 Copy</button>
            </div>
            <div class="content-body">
                <div class="prompt-text" id="prompt-text">{{ prompt.content }}</div>
            </div>
        </div>
        
        {% if share_info %}
        <div class="share-info">
            <strong>Share Info:</strong> 
            This prompt was shared on {{ share_info.created_at_readable[:10] }}.
            {% if share_info.expires_at_readable %}
            Share expires on {{ share_info.expires_at_readable[:10] }}.
            {% else %}
            This share link does not expire.
            {% endif %}
        </div>
        {% endif %}
        
        <div class="footer">
            <p>Powered by <a href="/">PromptBin</a> - Your local-first prompt management tool</p>
            <p style="margin-top: 0.5rem;">
                <a href="/">Browse More Prompts</a> | 
                <a href="/create">Create Your Own</a>
            </p>
        </div>
    </div>
    
    <script>
        // Highlight template variables
        document.addEventListener('DOMContentLoaded', function() {
            hljs.highlightAll();
            
            const promptText = document.getElementById('prompt-text');
            promptText.innerHTML = promptText.innerHTML.replace(
                /\{\{([^}]+)\}\}/g, 
                '<span class="template-var">{' + '{$1}' + '}</span>'
            );
        });
        
        // Copy functionality
        function copyToClipboard() {
            const promptText = document.getElementById('prompt-text');
            const textToCopy = promptText.textContent;
            
            navigator.clipboard.writeText(textToCopy).then(function() {
                showToast('Prompt content copied to clipboard!');
            }).catch(function(err) {
                console.error('Could not copy text: ', err);
                showToast('Failed to copy content', 'error');
            });
        }
        
        function showToast(message, type = 'success') {
            const toast = document.createElement('div');
            toast.className = 'toast';
            toast.textContent = message;
            
            if (type === 'error') {
                toast.style.background = '#dc2626';
            }
            
            document.body.appendChild(toast);
            
            // Trigger animation
            setTimeout(() => toast.classList.add('show'), 10);
            
            // Remove after delay
            setTimeout(() => {
                toast.classList.remove('show');
                setTimeout(() => document.body.removeChild(toast), 300);
            }, 3000);
        }
    </script>
</body>
</html>