import * as __WEBPACK_EXTERNAL_MODULE__tachybase_client__ from "@tachybase/client";
import * as __WEBPACK_EXTERNAL_MODULE_axios_mock_adapter__ from "axios-mock-adapter";
var collections_namespaceObject = JSON.parse('[{"key":"h7b9i8khc3q","name":"users","inherit":false,"hidden":false,"description":null,"category":[],"namespace":"users.users","duplicator":{"dumpable":"optional","with":"rolesUsers"},"sortable":"sort","model":"UserModel","createdBy":true,"updatedBy":true,"logging":true,"from":"db2cm","title":"{{t(\\"Users\\")}}","rawTitle":"{{t(\\"Users\\")}}","fields":[{"uiSchema":{"type":"number","title":"{{t(\\"ID\\")}}","x-component":"InputNumber","x-read-pretty":true,"rawTitle":"{{t(\\"ID\\")}}"},"key":"ffp1f2sula0","name":"id","type":"bigInt","interface":"id","description":null,"collectionName":"users","parentKey":null,"reverseKey":null,"autoIncrement":true,"primaryKey":true,"allowNull":false},{"uiSchema":{"type":"string","title":"{{t(\\"Nickname\\")}}","x-component":"Input","rawTitle":"{{t(\\"Nickname\\")}}"},"key":"vrv7yjue90g","name":"nickname","type":"string","interface":"input","description":null,"collectionName":"users","parentKey":null,"reverseKey":null},{"uiSchema":{"type":"string","title":"{{t(\\"Username\\")}}","x-component":"Input","x-validator":{"username":true},"required":true,"rawTitle":"{{t(\\"Username\\")}}"},"key":"2ccs6evyrub","name":"username","type":"string","interface":"input","description":null,"collectionName":"users","parentKey":null,"reverseKey":null,"unique":true},{"uiSchema":{"type":"string","title":"{{t(\\"Email\\")}}","x-component":"Input","x-validator":"email","required":true,"rawTitle":"{{t(\\"Email\\")}}"},"key":"rrskwjl5wt1","name":"email","type":"string","interface":"email","description":null,"collectionName":"users","parentKey":null,"reverseKey":null,"unique":true},{"key":"t09bauwm0wb","name":"roles","type":"belongsToMany","interface":"m2m","description":null,"collectionName":"users","parentKey":null,"reverseKey":null,"target":"roles","foreignKey":"userId","otherKey":"roleName","onDelete":"CASCADE","sourceKey":"id","targetKey":"name","through":"rolesUsers","uiSchema":{"type":"array","title":"{{t(\\"Roles\\")}}","x-component":"AssociationField","x-component-props":{"multiple":true,"fieldNames":{"label":"title","value":"name"}}}},{"key":"1pz0art9mt7","name":"f_n2fu6hvprct","type":"string","interface":"select","description":null,"collectionName":"t_vwpds9fs4xs","parentKey":null,"reverseKey":null,"uiSchema":{"enum":[{"value":"test1","label":"test1"},{"value":"test2","label":"test2"}],"type":"string","x-component":"Select","title":"test"}}]},{"key":"pqnenvqrzxr","name":"roles","inherit":false,"hidden":false,"description":null,"category":[],"namespace":"acl.acl","duplicator":{"dumpable":"required","with":"uiSchemas"},"autoGenId":false,"model":"RoleModel","filterTargetKey":"name","sortable":true,"from":"db2cm","title":"{{t(\\"Roles\\")}}","rawTitle":"{{t(\\"Roles\\")}}","fields":[{"uiSchema":{"type":"string","title":"{{t(\\"Role UID\\")}}","x-component":"Input","rawTitle":"{{t(\\"Role UID\\")}}"},"key":"jbz9m80bxmp","name":"name","type":"uid","interface":"input","description":null,"collectionName":"roles","parentKey":null,"reverseKey":null,"prefix":"r_","primaryKey":true},{"uiSchema":{"type":"string","title":"{{t(\\"Role name\\")}}","x-component":"Input","rawTitle":"{{t(\\"Role name\\")}}"},"key":"faywtz4sf3u","name":"title","type":"string","interface":"input","description":null,"collectionName":"roles","parentKey":null,"reverseKey":null,"unique":true,"translation":true},{"key":"1enkovm9sye","name":"description","type":"string","interface":null,"description":null,"collectionName":"roles","parentKey":null,"reverseKey":null}]}]');
function createApp(Demo) {
    let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, mocks = arguments.length > 2 ? arguments[2] : void 0;
    class MyPlugin extends __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Plugin {
        async load() {
            this.app.dataSourceManager.addDataSource(__WEBPACK_EXTERNAL_MODULE__tachybase_client__.LocalDataSource, {
                key: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.DEFAULT_DATA_SOURCE_KEY,
                displayName: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.DEFAULT_DATA_SOURCE_TITLE,
                collections: collections_namespaceObject
            });
        }
    }
    const app = new __WEBPACK_EXTERNAL_MODULE__tachybase_client__.Application({
        apiClient: {
            baseURL: 'http://localhost:8000'
        },
        providers: [
            Demo
        ],
        ...options,
        components: {
            ...options.components,
            DataBlockProvider: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.DataBlockProvider,
            CardItem: __WEBPACK_EXTERNAL_MODULE__tachybase_client__.CardItem
        },
        plugins: [
            __WEBPACK_EXTERNAL_MODULE__tachybase_client__.CollectionPlugin,
            MyPlugin
        ],
        designable: true
    });
    const mock = new __WEBPACK_EXTERNAL_MODULE_axios_mock_adapter__["default"](app.apiClient.axios);
    Object.entries(mocks).forEach((param)=>{
        let [url, data] = param;
        mock.onGet(url).reply(async (config)=>{
            const res = 'function' == typeof data ? data(config) : data;
            return [
                200,
                res
            ];
        });
        mock.onPost(url).reply(async (config)=>{
            const res = 'function' == typeof data ? data(config) : data;
            return [
                200,
                res
            ];
        });
    });
    const Root = app.getRootComponent();
    return Root;
}
export { createApp };
