#include "zori.h"
#include "zori_widget.h"
#include "zori_caption.h"
#include "zori_page.h"


struct zori_page * zori_widget_to_page(struct zori_widget * widget) {
  if (!zori_widget_is_type(widget, ZORI_WIDGET_TYPE_PAGE)) return NULL;
  return ZORI_CONTAINER_OF(widget, struct zori_page, widget);
}

struct zori_page * zori_page_new(zori_id id, struct zori_widget * parent) {
  struct zori_page * page = NULL;
  if (!parent) return NULL;
  page = calloc(1, sizeof(*page));
  if (!page) return NULL;
  zori_widget_initall(&page->widget, ZORI_WIDGET_TYPE_PAGE, id, parent, 
                      NULL, NULL, NULL, 0); 
  return page;
}


zori_id zori_new_page(zori_id id, zori_id parent_id) {
  struct zori_widget * parent = zori_get_widget(parent_id);  
  struct zori_page   * page   = zori_page_new(id, parent);
  if (!page) return ZORI_ID_ENOMEM;
  return page->widget.id;
}




