{
    "version": "1.0.0",
    "layout_name": "plugin_settings",
    "permissions": [
        "core.plugins.update"
    ],
    "extends": "_admin_base",
    "meta": {
        "title": "$t:gnuboard7-hello_plugin.settings.title",
        "description": "$t:gnuboard7-hello_plugin.settings.description"
    },
    "data_sources": [
        {
            "id": "settings",
            "label_key": "$t:gnuboard7-hello_plugin.editor.data_source.settings",
            "type": "api",
            "endpoint": "/api/admin/plugins/{{route.identifier}}/settings",
            "method": "GET",
            "auto_fetch": true,
            "auth_required": true,
            "initLocal": "form",
            "refetchOnMount": true
        }
    ],
    "slots": {
        "content": [
            {
                "id": "plugin_settings_content",
                "type": "basic",
                "name": "Div",
                "dataKey": "form",
                "trackChanges": true,
                "props": {
                    "className": "admin-page-content-responsive"
                },
                "children": [
                    {
                        "id": "page_header",
                        "type": "composite",
                        "name": "PageHeader",
                        "props": {
                            "title": "$t:gnuboard7-hello_plugin.settings.title",
                            "description": "$t:gnuboard7-hello_plugin.settings.description",
                            "backPath": "/admin/plugins",
                            "backLabel": "$t:admin.plugins.back_to_list"
                        }
                    },
                    {
                        "id": "settings_form",
                        "type": "basic",
                        "name": "Div",
                        "props": {
                            "className": "mt-6 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700"
                        },
                        "children": [
                            {
                                "id": "settings_fields",
                                "type": "basic",
                                "name": "Div",
                                "props": {
                                    "className": "p-6 space-y-6"
                                },
                                "children": [
                                    {
                                        "id": "field_log_enabled",
                                        "type": "basic",
                                        "name": "Div",
                                        "props": {
                                            "className": "flex-start gap-3"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Input",
                                                "props": {
                                                    "type": "checkbox",
                                                    "name": "log_enabled",
                                                    "className": "mt-1 h-4 w-4 rounded text-blue-600"
                                                }
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Label",
                                                        "props": {
                                                            "className": "form-label"
                                                        },
                                                        "text": "$t:gnuboard7-hello_plugin.settings.fields.log_enabled.label"
                                                    },
                                                    {
                                                        "type": "basic",
                                                        "name": "P",
                                                        "props": {
                                                            "className": "form-hint"
                                                        },
                                                        "text": "$t:gnuboard7-hello_plugin.settings.fields.log_enabled.hint"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": "footer_buttons",
                        "type": "basic",
                        "name": "Div",
                        "props": {
                            "className": "sticky-footer-buttons"
                        },
                        "children": [
                            {
                                "id": "cancel_button",
                                "type": "basic",
                                "name": "Button",
                                "props": {
                                    "type": "button",
                                    "className": "btn btn-secondary"
                                },
                                "actions": [
                                    {
                                        "type": "click",
                                        "handler": "navigate",
                                        "params": {
                                            "path": "/admin/plugins"
                                        }
                                    }
                                ],
                                "children": [
                                    {
                                        "type": "basic",
                                        "name": "Span",
                                        "text": "$t:common.cancel"
                                    }
                                ]
                            },
                            {
                                "id": "save_button",
                                "type": "basic",
                                "name": "Button",
                                "props": {
                                    "type": "button",
                                    "disabled": "{{!_local.hasChanges || _local.isSaving}}",
                                    "className": "btn btn-primary flex-center gap-1.5"
                                },
                                "actions": [
                                    {
                                        "type": "click",
                                        "handler": "sequence",
                                        "actions": [
                                            {
                                                "handler": "setState",
                                                "params": {
                                                    "target": "local",
                                                    "isSaving": true,
                                                    "errors": null
                                                }
                                            },
                                            {
                                                "handler": "apiCall",
                                                "auth_required": true,
                                                "target": "/api/admin/plugins/{{route.identifier}}/settings",
                                                "params": {
                                                    "method": "PUT",
                                                    "body": "{{_local.form}}"
                                                },
                                                "onSuccess": [
                                                    {
                                                        "handler": "setState",
                                                        "params": {
                                                            "target": "local",
                                                            "isSaving": false,
                                                            "hasChanges": false
                                                        }
                                                    },
                                                    {
                                                        "handler": "toast",
                                                        "params": {
                                                            "type": "success",
                                                            "message": "$t:admin.plugins.settings.save_success"
                                                        }
                                                    },
                                                    {
                                                        "handler": "refetchDataSource",
                                                        "params": {
                                                            "dataSourceId": "settings"
                                                        }
                                                    }
                                                ],
                                                "onError": [
                                                    {
                                                        "handler": "setState",
                                                        "params": {
                                                            "target": "local",
                                                            "isSaving": false,
                                                            "errors": "{{$error.errors}}"
                                                        }
                                                    },
                                                    {
                                                        "handler": "toast",
                                                        "params": {
                                                            "type": "error",
                                                            "message": "$t:admin.plugins.settings.save_error"
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ],
                                "children": [
                                    {
                                        "type": "basic",
                                        "name": "Span",
                                        "if": "{{!_local.isSaving}}",
                                        "text": "$t:common.save"
                                    },
                                    {
                                        "type": "basic",
                                        "name": "Span",
                                        "if": "{{_local.isSaving}}",
                                        "text": "$t:common.saving"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    },
    "schema": {
        "log_enabled": {
            "type": "boolean",
            "default": true,
            "label": "$t:gnuboard7-hello_plugin.settings.fields.log_enabled.label",
            "hint": "$t:gnuboard7-hello_plugin.settings.fields.log_enabled.hint"
        }
    }
}
