# Script to add the beach_design route to the end of admin_routes.py

beach_design_route = '''

@admin_bp.route('/beaches/<beach_id>/design', methods=['GET'])
@login_required
def beach_design(beach_id):
    """Full screen beach design page"""
    # Check if user is logged in and is admin
    if not session.get('is_admin'):
        flash('You must be logged in as an administrator to access this page.', 'error')
        return redirect(url_for('admin.admin_login'))
    
    try:
        # Redirect to the static Vue application with just the beach ID
        return redirect(f"/static/BeachDesign/index.html?beach_id={beach_id}")
        
    except Exception as e:
        error_msg = f'Error loading beach design: {str(e)}'
        print(f"BEACH DESIGN ERROR: {error_msg}")
        flash(error_msg, 'error')
        # Redirect back to beach edit page
        return redirect(url_for('admin.edit_beach', beach_id=beach_id))
'''

# Append the route to the file
with open(r'd:\bookbeach\backend\app\routes\admin_routes.py', 'a', encoding='utf-8') as f:
    f.write(beach_design_route)

print("Successfully added beach_design route to admin_routes.py")