<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ _('device_edit_title') }} - iAccess Terminal</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #667eea;
            --secondary-color: #764ba2;
            --success-color: #28a745;
            --warning-color: #ffc107;
            --danger-color: #dc3545;
            --info-color: #17a2b8;
            --dark-color: #343a40;
            --light-color: #f8f9fa;
        }

        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        .navbar {
            background: rgba(255, 255, 255, 0.95) !important;
            backdrop-filter: blur(10px);
            box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
        }

        .navbar-brand {
            font-weight: 700;
            color: var(--primary-color) !important;
        }

        .nav-link {
            color: var(--dark-color) !important;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .nav-link:hover {
            color: var(--primary-color) !important;
            transform: translateY(-1px);
        }

        .main-container {
            margin-top: 80px;
            padding: 20px;
        }

        .device-form-card {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            max-width: 600px;
            margin: 0 auto;
        }

        .form-header {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: white;
            padding: 30px;
            border-radius: 20px 20px 0 0;
            text-align: center;
        }

        .form-header h2 {
            margin: 0;
            font-size: 1.8rem;
            font-weight: 700;
        }

        .form-header p {
            margin: 10px 0 0 0;
            opacity: 0.9;
            font-size: 1rem;
        }

        .form-body {
            padding: 40px;
        }

        .form-group {
            margin-bottom: 25px;
        }

        .form-label {
            font-weight: 600;
            color: var(--dark-color);
            margin-bottom: 8px;
            display: flex;
            align-items: center;
        }

        .form-label i {
            margin-right: 8px;
            color: var(--primary-color);
            width: 20px;
        }

        .form-control, .form-select {
            border-radius: 12px;
            border: 2px solid #e9ecef;
            padding: 15px 20px;
            font-size: 1rem;
            transition: all 0.3s ease;
            background: rgba(255, 255, 255, 0.9);
        }

        .form-control:focus, .form-select:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
            background: white;
        }

        .btn-modern {
            border-radius: 12px;
            padding: 15px 30px;
            font-weight: 600;
            font-size: 1rem;
            transition: all 0.3s ease;
            border: none;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .btn-primary-modern {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: white;
        }

        .btn-primary-modern:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
            color: white;
        }

        .btn-secondary-modern {
            background: linear-gradient(135deg, #6c757d, #495057);
            color: white;
        }

        .btn-secondary-modern:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(108, 117, 125, 0.4);
            color: white;
        }

        .btn-danger-modern {
            background: linear-gradient(135deg, var(--danger-color), #e74c3c);
            color: white;
        }

        .btn-danger-modern:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(220, 53, 69, 0.4);
            color: white;
        }

        .device-type-info {
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
            border: 1px solid rgba(102, 126, 234, 0.2);
            border-radius: 12px;
            padding: 20px;
            margin-bottom: 25px;
        }

        .device-type-info h6 {
            color: var(--primary-color);
            font-weight: 600;
            margin-bottom: 10px;
        }

        .device-type-info p {
            margin: 0;
            color: #6c757d;
            font-size: 0.9rem;
        }

        .alert {
            border-radius: 12px;
            border: none;
            padding: 15px 20px;
        }

        @media (max-width: 768px) {
            .main-container {
                margin-top: 60px;
                padding: 10px;
            }
            
            .form-body {
                padding: 30px 20px;
            }
            
            .form-header {
                padding: 25px 20px;
            }
            
            .form-header h2 {
                font-size: 1.5rem;
            }
        }
    </style>
</head>
<body>
    <!-- Navigation -->
    <nav class="navbar navbar-expand-lg fixed-top">
        <div class="container">
            <a class="navbar-brand" href="https://monicont.com" target="_blank">
                <img src="{{ url_for('static', filename='img/monicont_logo.png') }}" alt="Logo" style="width: 120px; height: auto;" class="me-3">
            </a>
            
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('home') }}">
                            <i class="fas fa-home me-1"></i>{{ _('dashboard') }}
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="{{ url_for('devices') }}">
                            <i class="fas fa-microchip me-1"></i>{{ _('devices') }}
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('users') }}">
                            <i class="fas fa-users me-1"></i>{{ _('users_title') }}
                        </a>
                    </li>
                </ul>
                
                <ul class="navbar-nav">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
                            <i class="fas fa-user-circle me-1"></i>{{ user_name }}
                        </a>
                        <ul class="dropdown-menu">
                            <li><a class="dropdown-item" href="#"><i class="fas fa-user me-2"></i>{{ _('profile') }}</a></li>
                            <li><a class="dropdown-item" href="#"><i class="fas fa-cog me-2"></i>{{ _('settings') }}</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="{{ url_for('logout') }}"><i class="fas fa-sign-out-alt me-2"></i>{{ _('logout') }}</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <div class="main-container">
        <div class="container">
            <div class="device-form-card">
                <div class="form-header">
                    <h2><i class="fas fa-edit me-2"></i>{{ _('device_edit_title') }}</h2>
                    <p>{{ _('device_edit_subtitle') }}</p>
                </div>
                
                <div class="form-body">
                    {% with messages = get_flashed_messages(with_categories=true) %}
                        {% if messages %}
                            {% for category, message in messages %}
                                <div class="alert alert-{{ 'danger' if category == 'error' else 'success' }} alert-dismissible fade show" role="alert">
                                    <i class="fas fa-{{ 'exclamation-triangle' if category == 'error' else 'check-circle' }} me-2"></i>
                                    {{ message }}
                                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                                </div>
                            {% endfor %}
                        {% endif %}
                    {% endwith %}

                    <form method="POST">
                        <div class="form-group">
                            <label for="ad" class="form-label">
                                <i class="fas fa-microchip"></i>{{ _('device_name') }}
                            </label>
                            <input type="text" class="form-control" id="ad" name="ad" 
                                   value="{{ cihaz['ad'] if cihaz['ad'] else (cihaz['device_name'] if cihaz else '') }}" required>
                        </div>

                        <div class="form-group">
                            <label for="seri_no" class="form-label">
                                <i class="fas fa-barcode"></i>{{ _('device_serial') }}
                            </label>
                            <input type="text" class="form-control" id="seri_no" name="seri_no" 
                                   value="{{ cihaz['seri_no'] if cihaz['seri_no'] else (cihaz['serial_number'] if cihaz else '') }}" required>
                        </div>

                        <div class="form-group">
                            <label for="tcp_tipi" class="form-label">
                                <i class="fas fa-network-wired"></i>{{ _('device_tcp_type') }}
                            </label>
                            <select class="form-select" id="tcp_tipi" name="tcp_tipi" required onchange="showIpField()">
                                <option value="">{{ _('device_tcp_select') }}</option>
                                <option value="server" {{ 'selected' if cihaz and (cihaz['tcp_tipi'] == 'server' or cihaz['device_type'] == 'server') else '' }}>{{ _('device_tcp_server') }}</option>
                                <option value="client" {{ 'selected' if cihaz and (cihaz['tcp_tipi'] == 'client' or cihaz['device_type'] == 'client') else '' }}>{{ _('device_tcp_client') }}</option>
                            </select>
                        </div>

                        <div class="device-type-info" id="device_info" style="display: none;">
                            <h6><i class="fas fa-info-circle me-2"></i>{{ _('device_type_info') }}</h6>
                            <p id="device_info_text"></p>
                        </div>

                        <div class="form-group" id="ip_field" style="display: none;">
                            <label for="ip_adresi" class="form-label">
                                <i class="fas fa-globe"></i>{{ _('device_ip') }}
                            </label>
                            <input type="text" class="form-control" id="ip_adresi" name="ip_adresi" 
                                   value="{{ cihaz['ip_adresi'] if cihaz['ip_adresi'] else (cihaz['ip_address'] if cihaz else '') }}"
                                   placeholder="{{ _('device_ip_placeholder') }}">
                        </div>

                        <div class="d-grid gap-3 mt-4">
                            <button type="submit" class="btn btn-primary-modern btn-modern">
                                <i class="fas fa-save me-2"></i>{{ _('update') }}
                            </button>
                            <a href="{{ url_for('devices') }}" class="btn btn-secondary-modern btn-modern">
                                <i class="fas fa-arrow-left me-2"></i>{{ _('cancel') }}
                            </a>
                            <button type="button" class="btn btn-danger-modern btn-modern" onclick="deleteDevice()">
                                <i class="fas fa-trash me-2"></i>{{ _('delete') }}
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <script>
        function showIpField() {
            var tcp = document.getElementById('tcp_tipi').value;
            var ipField = document.getElementById('ip_field');
            var deviceInfo = document.getElementById('device_info');
            var deviceInfoText = document.getElementById('device_info_text');
            
            if (tcp === 'client') {
                ipField.style.display = 'block';
                deviceInfo.style.display = 'block';
                deviceInfoText.innerHTML = '{{ _("device_client_info") }}';
            } else if (tcp === 'server') {
                ipField.style.display = 'none';
                deviceInfo.style.display = 'block';
                deviceInfoText.innerHTML = '{{ _("device_server_info") }}';
            } else {
                ipField.style.display = 'none';
                deviceInfo.style.display = 'none';
            }
        }

        function deleteDevice() {
            if (confirm('{{ _("confirm_delete_device") }}')) {
                const form = document.createElement('form');
                form.method = 'POST';
                form.action = '{{ url_for("delete_device", device_id=cihaz["id"]) }}';
                document.body.appendChild(form);
                form.submit();
            }
        }

        document.addEventListener('DOMContentLoaded', function() {
            showIpField();
        });
    </script>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html> 