(in-package :com.tee-it-up-golf.web)

(defun create-frontend-entry-points ()
  (defentry-point "^(index.ucw|)$" (:application (get-golf-application :frontend)
						:class regexp-dispatcher)
      ()
    (call 'golf-frontend-window))

  (defentry-point "^(audio.ucw)$" (:application (get-golf-application :frontend)
						:class regexp-dispatcher)
      (file)
    (call 'audio-file-window
	  :audio-file (make-instance 'audio-file
				     :type "application/ogg"
				     :data file)))

  (defentry-point "^archive/(\\d{4})/(\\d{1,2})/(\\d{1,2})$"
      (:application (get-golf-application :frontend) :class regexp-dispatcher)
      ()
    (let ((year  (parse-integer (aref *dispatcher-registers* 0)))
	  (month (parse-integer (aref *dispatcher-registers* 1)))
	  (day   (parse-integer (aref *dispatcher-registers* 2))))
      (let ((window (golf-util::initialize-window
		     (make-instance 'golf-frontend-window))))
	(setf (container.current-component-key (window-body window))
	      'archive)
	(call-component (container.current-component (window-body window))
			(make-instance 'frontend-show-viewer
				       :item (car (get-shows-by 'show-date
								(encode-universal-time 0 0 0 day month year)
								nil
								:limit 1))))))))

(defun create-backend-entry-points ()
  (defentry-point "^(admin.ucw|)$" (:application (get-golf-application :backend)
						:class regexp-dispatcher)
      ()
    (call 'golf-admin-window)))

(defun create-entry-points ()
  (create-frontend-entry-points)
  (create-backend-entry-points))
