import { Col } from "./DocCreatorMenu";
import { FieldSettings } from "./FieldTypes/Field";
import { Template } from "./Template";
import { TemplateLayouts } from "./TemplateBackend";

export class TemplateManager {

    templates: Template[] = [];

    constructor(templateSettings: FieldSettings[]) {
        this.templates = this.initializeTemplates(templateSettings);
    }

    initializeTemplates = (templateSettings: FieldSettings[]): Template[] => {
        const initializedTemplates: Template[] = [];
        templateSettings.forEach(settings => initializedTemplates.push(new Template(settings)));
        return initializedTemplates;
    }

    /**
     * Provides a text summary of content currently filled into a template, formatted for GPT analysis.
     * @param template the template to be summarized
     */
    getContentSummary = (template: Template) => {
        let summary: string = '';
        template.contentFields.forEach(field => {
            summary += `--- Field #${field.getID} (title: ${field.getTitle()}): ${field.getContent() ?? ''} ---`;
        });
        return summary;
    }

    getValidTemplates = (cols: Col[]): Template[] => {
        return this.templates.filter(template => template.isValidTemplate(cols));
    }
}