import { Plugin } from "../application/Plugin.mjs";
import { DataSource } from "../data-source/data-source/DataSource.mjs";
import { DEFAULT_DATA_SOURCE_KEY, DEFAULT_DATA_SOURCE_TITLE } from "../data-source/data-source/DataSourceManager.mjs";
import { CheckboxFieldInterface, CheckboxGroupFieldInterface, ChinaRegionFieldInterface, CollectionSelectFieldInterface, ColorFieldInterface, CreatedAtFieldInterface, CreatedByFieldInterface, DatetimeFieldInterface, EmailFieldInterface, IconFieldInterface, IdFieldInterface, InputFieldInterface, IntegerFieldInterface, JsonFieldInterface, LinkToFieldInterface, M2MFieldInterface, M2OFieldInterface, MarkdownFieldInterface, MultipleSelectFieldInterface, NanoidFieldInterface, NumberFieldInterface, O2MFieldInterface, O2OFieldInterface, OBOFieldInterface, OHOFieldInterface, PasswordFieldInterface, PercentFieldInterface, PhoneFieldInterface, RadioGroupFieldInterface, RichTextFieldInterface, SelectFieldInterface, SortFieldInterface, SubTableFieldInterface, TableoidFieldInterface, TextareaFieldInterface, TimeFieldInterface, UUIDFieldInterface, UnixTimestampFieldInterface, UpdatedAtFieldInterface, UpdatedByFieldInterface, UrlFieldInterface } from "./interfaces/index.mjs";
import { InheritanceCollectionMixin } from "./mixins/InheritanceCollectionMixin.mjs";
import { ExpressionCollectionTemplate, GeneralCollectionTemplate, ImportCollectionTemplate, SqlCollectionTemplate, TreeCollectionTemplate, ViewCollectionTemplate } from "./templates/index.mjs";
import { ImportXlsxTemplate } from "./templates/xlsx.mjs";
class MainDataSource extends DataSource {
    async getDataSource() {
        var _service_data;
        const service = await this.app.apiClient.request({
            resource: 'collections',
            action: 'list',
            params: {
                paginate: false,
                appends: [
                    'fields',
                    'category'
                ],
                filter: {},
                sort: [
                    'sort'
                ]
            }
        });
        const collections = (null == service ? void 0 : null == (_service_data = service.data) ? void 0 : _service_data.data) || [];
        return {
            collections
        };
    }
}
class CollectionPlugin extends Plugin {
    async load() {
        this.dataSourceManager.addCollectionMixins([
            InheritanceCollectionMixin
        ]);
        this.addFieldInterfaces();
        this.addCollectionTemplates();
        this.addFieldInterfaces();
        this.addFieldInterfaceGroups();
        this.dataSourceManager.addDataSource(MainDataSource, {
            key: DEFAULT_DATA_SOURCE_KEY,
            displayName: DEFAULT_DATA_SOURCE_TITLE
        });
    }
    addFieldInterfaceGroups() {
        this.dataSourceManager.addFieldInterfaceGroups({
            basic: {
                label: '{{t("Basic")}}'
            },
            choices: {
                label: '{{t("Choices")}}'
            },
            media: {
                label: '{{t("Media")}}'
            },
            datetime: {
                label: '{{t("Date & Time")}}'
            },
            relation: {
                label: '{{t("Relation")}}'
            },
            advanced: {
                label: '{{t("Advanced type")}}'
            },
            systemInfo: {
                label: '{{t("System info")}}'
            },
            others: {
                label: '{{t("Others")}}'
            }
        });
    }
    addFieldInterfaces() {
        this.dataSourceManager.addFieldInterfaces([
            CheckboxFieldInterface,
            CheckboxGroupFieldInterface,
            ChinaRegionFieldInterface,
            CollectionSelectFieldInterface,
            ColorFieldInterface,
            CreatedAtFieldInterface,
            CreatedByFieldInterface,
            DatetimeFieldInterface,
            EmailFieldInterface,
            IconFieldInterface,
            IdFieldInterface,
            InputFieldInterface,
            IntegerFieldInterface,
            JsonFieldInterface,
            LinkToFieldInterface,
            M2MFieldInterface,
            M2OFieldInterface,
            MarkdownFieldInterface,
            MultipleSelectFieldInterface,
            NumberFieldInterface,
            O2MFieldInterface,
            O2OFieldInterface,
            OHOFieldInterface,
            OBOFieldInterface,
            PasswordFieldInterface,
            PercentFieldInterface,
            PhoneFieldInterface,
            RadioGroupFieldInterface,
            RichTextFieldInterface,
            SelectFieldInterface,
            SubTableFieldInterface,
            TableoidFieldInterface,
            TextareaFieldInterface,
            TimeFieldInterface,
            UpdatedAtFieldInterface,
            UpdatedByFieldInterface,
            UrlFieldInterface,
            SortFieldInterface,
            UUIDFieldInterface,
            NanoidFieldInterface,
            UnixTimestampFieldInterface
        ]);
    }
    addCollectionTemplates() {
        this.dataSourceManager.addCollectionTemplates([
            GeneralCollectionTemplate,
            ExpressionCollectionTemplate,
            SqlCollectionTemplate,
            TreeCollectionTemplate,
            ViewCollectionTemplate,
            ImportCollectionTemplate,
            ImportXlsxTemplate
        ]);
    }
}
export { CollectionPlugin };
