#!/usr/bin/env python3
"""Simple HTTP server for the Pharma Global website."""

import http.server
import socketserver
import os
import sys
from pathlib import Path

PORT = 8000
DIRECTORY = Path(__file__).parent

class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, directory=str(DIRECTORY), **kwargs)
    
    def end_headers(self):
        # Add headers to prevent caching issues
        self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
        self.send_header('Access-Control-Allow-Origin', '*')
        super().end_headers()

if __name__ == '__main__':
    os.chdir(DIRECTORY)
    with socketserver.TCPServer(("", PORT), MyHTTPRequestHandler) as httpd:
        print(f"🚀 Server running at http://localhost:{PORT}")
        print(f"📁 Serving from: {DIRECTORY}")
        print("\nOpen these pages:")
        print(f"  • http://localhost:{PORT}/Inicio.dc.html")
        print(f"  • http://localhost:{PORT}/Nosotros.dc.html")
        print(f"  • http://localhost:{PORT}/Servicios.dc.html")
        print(f"  • http://localhost:{PORT}/Calidad-Logistica.dc.html")
        print(f"  • http://localhost:{PORT}/Contactanos.dc.html")
        print("\nPress Ctrl+C to stop the server.\n")
        try:
            httpd.serve_forever()
        except KeyboardInterrupt:
            print("\n✅ Server stopped.")
            sys.exit(0)
