import os

from .commit_page import CommitPage
from .file_page import FilePage
from .overview_page import OverviewPage
from .log_page import LogPage
from .tree_page import TreePage

class PageFactory:
    def __init__(self, out_dir, name, content_subdir):
        self.out_dir = out_dir
        self.name = name
        self.content_subdir = content_subdir

    def new_commit(self, commit):
        return CommitPage(self.out_dir, self.name, commit, self.content_subdir)

    def new_file(self, commit, path):
        filename = os.path.basename(path)
        dir = os.path.dirname(path)
        return FilePage(self.out_dir, self.name, commit, filename, dir, self.content_subdir)

    def new_overview(self, branches, tags, head):
        return OverviewPage(self.out_dir, self.name, branches, tags, self.content_subdir, head)

    def new_log(self, commits, branches, tags):
        return LogPage(self.out_dir, self.name, commits, branches, tags, self.content_subdir)

    def new_tree(self, commit, tree_segment, repo):
        return TreePage(self.out_dir, self.name, commit, tree_segment, repo, self.content_subdir)
