{
    "version": "1.0.0",
    "layout_name": "admin_board_form",
    "permissions": [
        "sirsoft-board.boards.read"
    ],
    "extends": "_admin_base",
    "meta": {
        "title": "{{route?.slug ? '$t:sirsoft-board.admin.form.title_edit' : '$t:sirsoft-board.admin.form.title_create'}}",
        "description": "$t:sirsoft-board.admin.form.description"
    },
    "computed": {
        "isReadOnly": "{{!!route?.slug && !!boards?.data && boards?.data?.abilities?.can_update !== true}}"
    },
    "state": {
        "activeTab": "section_basic_card",
        "isSaving": false,
        "hasChanges": false,
        "showCancelConfirmModal": false,
        "form": [],
        "isDataLoaded": false,
        "managerSearchResults": [],
        "stepSearchResults": []
    },
    "transition_overlay": {
        "wait_for": [
            "roles",
            "notification_channels"
        ]
    },
    "data_sources": [
        {
            "id": "boards",
            "label_key": "$t:sirsoft-board.editor.data_source.boards",
            "type": "api",
            "endpoint": "/api/modules/sirsoft-board/admin/boards/form-data",
            "method": "GET",
            "auto_fetch": true,
            "auth_required": true,
            "cache": false,
            "loading_strategy": "blocking",
            "params": {
                "board_slug": "{{route?.slug}}",
                "copy_id": "{{query?.copy_id}}"
            },
            "initLocal": "form",
            "refetchOnMount": true,
            "errorHandling": {
                "403": {
                    "handler": "showErrorPage",
                    "params": {
                        "target": "content"
                    }
                },
                "404": {
                    "handler": "showErrorPage",
                    "params": {
                        "target": "content"
                    }
                }
            }
        },
        {
            "id": "roles",
            "label_key": "$t:sirsoft-board.editor.data_source.roles",
            "type": "api",
            "endpoint": "/api/admin/roles/active",
            "method": "GET",
            "auto_fetch": true,
            "auth_required": true
        },
        {
            "id": "availableChannels",
            "label_key": "$t:sirsoft-board.editor.data_source.availableChannels",
            "type": "api",
            "endpoint": "/api/admin/notification-channels",
            "method": "GET",
            "auto_fetch": true,
            "auth_required": true,
            "fallback": {
                "data": {
                    "channels": []
                }
            }
        }
    ],
    "slots": {
        "content": [
            {
                "id": "board_form_wrapper",
                "type": "basic",
                "name": "Div",
                "dataKey": "form",
                "trackChanges": true,
                "props": {
                    "className": "admin-page-content"
                },
                "children": [
                    {
                        "id": "read_only_banner",
                        "type": "basic",
                        "name": "Div",
                        "if": "{{_computed.isReadOnly}}",
                        "props": {
                            "className": "alert-warning"
                        },
                        "children": [
                            {
                                "type": "basic",
                                "name": "Icon",
                                "props": {
                                    "name": "lock",
                                    "className": "w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0"
                                }
                            },
                            {
                                "type": "basic",
                                "name": "Span",
                                "props": {
                                    "className": "text-warning-soft"
                                },
                                "text": "$t:sirsoft-board.admin.form.read_only_message"
                            }
                        ]
                    },
                    {
                        "id": "page_header",
                        "type": "basic",
                        "name": "Div",
                        "props": {
                            "className": "page-header-fullbleed"
                        },
                        "children": [
                            {
                                "type": "basic",
                                "name": "Div",
                                "children": [
                                    {
                                        "type": "basic",
                                        "name": "H1",
                                        "props": {
                                            "className": "page-title"
                                        },
                                        "text": "{{route?.slug ? '$t:sirsoft-board.admin.form.title_edit' : '$t:sirsoft-board.admin.form.title_create'}}"
                                    },
                                    {
                                        "type": "basic",
                                        "name": "P",
                                        "props": {
                                            "className": "page-description"
                                        },
                                        "text": "$t:sirsoft-board.admin.form.description"
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": "tab_navigation",
                        "type": "composite",
                        "name": "TabNavigationScroll",
                        "props": {
                            "className": "sticky-tab-nav tab-nav-default",
                            "activeTabId": "{{_local.activeTab ?? 'section_basic_card'}}",
                            "enableScrollSpy": true,
                            "scrollSpyOffset": 56,
                            "sectionIdPrefix": "",
                            "tabs": [
                                {
                                    "id": "section_basic_card",
                                    "label": "$t:sirsoft-board.admin.form.tabs.basic"
                                },
                                {
                                    "id": "section_permissions_card",
                                    "label": "$t:sirsoft-board.admin.form.tabs.permissions"
                                },
                                {
                                    "id": "section_list_card",
                                    "label": "$t:sirsoft-board.admin.form.tabs.list"
                                },
                                {
                                    "id": "section_post_card",
                                    "label": "$t:sirsoft-board.admin.form.tabs.post"
                                },
                                {
                                    "id": "section_notification_card",
                                    "label": "$t:sirsoft-board.admin.form.tabs.notification"
                                }
                            ]
                        }
                    },
                    {
                        "id": "validation_error",
                        "type": "basic",
                        "name": "Div",
                        "if": "{{_local.errors}}",
                        "props": {
                            "className": "pt-4"
                        },
                        "children": [
                            {
                                "type": "basic",
                                "name": "Div",
                                "props": {
                                    "className": "alert-danger"
                                },
                                "children": [
                                    {
                                        "type": "basic",
                                        "name": "Icon",
                                        "props": {
                                            "name": "triangle-exclamation",
                                            "className": "w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5"
                                        }
                                    },
                                    {
                                        "type": "basic",
                                        "name": "Div",
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "H3",
                                                "props": {
                                                    "className": "text-error-strong"
                                                },
                                                "text": "$t:sirsoft-board.admin.form.validation_error"
                                            },
                                            {
                                                "type": "basic",
                                                "name": "P",
                                                "if": "{{typeof _local.errors === 'string'}}",
                                                "props": {
                                                    "className": "text-error-soft mt-2"
                                                },
                                                "text": "{{_local.errors}}"
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Ul",
                                                "if": "{{typeof _local.errors === 'object' && Object.keys(_local.errors).length > 0}}",
                                                "props": {
                                                    "className": "mt-2 list-disc list-inside space-y-1"
                                                },
                                                "iteration": {
                                                    "source": "Object.entries(_local.errors ?? {}).flatMap(([field, messages]) => Array.isArray(messages) ? messages : [messages])",
                                                    "item_var": "message"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Li",
                                                        "props": {
                                                            "className": "text-error-soft"
                                                        },
                                                        "text": "{{message}}"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": "board_form",
                        "type": "basic",
                        "name": "Form",
                        "props": {
                            "id": "board_form"
                        },
                        "children": [
                            {
                                "id": "board_form_tab_content",
                                "type": "basic",
                                "name": "Div",
                                "props": {
                                    "className": "tab-content"
                                },
                                "children": [
                                    {
                                        "partial": "partials/admin_board_form/_tab_basic.json"
                                    },
                                    {
                                        "partial": "partials/admin_board_form/_tab_permissions.json"
                                    },
                                    {
                                        "partial": "partials/admin_board_form/_tab_list.json"
                                    },
                                    {
                                        "partial": "partials/admin_board_form/_tab_post.json"
                                    },
                                    {
                                        "partial": "partials/admin_board_form/_tab_notification.json"
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": "footer_buttons",
                        "type": "basic",
                        "name": "Div",
                        "props": {
                            "className": "sticky-footer-buttons-between"
                        },
                        "children": [
                            {
                                "id": "footer_list_button",
                                "type": "basic",
                                "name": "Button",
                                "props": {
                                    "type": "button",
                                    "className": "flex-center gap-2 px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 font-medium transition-colors"
                                },
                                "children": [
                                    {
                                        "type": "basic",
                                        "name": "Span",
                                        "text": "$t:common.list"
                                    }
                                ],
                                "actions": [
                                    {
                                        "type": "click",
                                        "handler": "navigate",
                                        "params": {
                                            "path": "/admin/boards"
                                        }
                                    }
                                ]
                            },
                            {
                                "type": "basic",
                                "name": "Div",
                                "props": {
                                    "className": "flex-center gap-3"
                                },
                                "children": [
                                    {
                                        "id": "footer_cancel_button",
                                        "type": "basic",
                                        "name": "Button",
                                        "props": {
                                            "type": "button",
                                            "className": "btn btn-secondary"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Span",
                                                "text": "$t:common.cancel"
                                            }
                                        ],
                                        "actions": [
                                            {
                                                "type": "click",
                                                "handler": "navigate",
                                                "params": {
                                                    "path": "/admin/boards"
                                                }
                                            }
                                        ]
                                    },
                                    {
                                        "id": "footer_save_button",
                                        "type": "basic",
                                        "name": "Button",
                                        "props": {
                                            "type": "button",
                                            "disabled": "{{_computed.isReadOnly || _local.isSaving || (!!route?.slug && !_local.hasChanges)}}",
                                            "className": "btn btn-primary flex-center gap-1.5"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Icon",
                                                "if": "{{_local.isSaving}}",
                                                "props": {
                                                    "name": "spinner",
                                                    "className": "spinner-sm"
                                                }
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Span",
                                                "text": "{{_local.isSaving ? '$t:sirsoft-board.common.saving' : '$t:sirsoft-board.common.save'}}"
                                            }
                                        ],
                                        "actions": [
                                            {
                                                "type": "click",
                                                "handler": "sequence",
                                                "params": {
                                                    "actions": [
                                                        {
                                                            "handler": "setState",
                                                            "params": {
                                                                "target": "local",
                                                                "isSaving": true
                                                            }
                                                        },
                                                        {
                                                            "handler": "apiCall",
                                                            "auth_required": true,
                                                            "target": "{{route?.slug ? '/api/modules/sirsoft-board/admin/boards/' + route.slug : '/api/modules/sirsoft-board/admin/boards'}}",
                                                            "params": {
                                                                "method": "{{route?.slug ? 'PUT' : 'POST'}}",
                                                                "body": "{{_local.form}}"
                                                            },
                                                            "onSuccess": [
                                                                {
                                                                    "handler": "setState",
                                                                    "params": {
                                                                        "target": "local",
                                                                        "isSaving": false,
                                                                        "hasChanges": false,
                                                                        "errors": null
                                                                    }
                                                                },
                                                                {
                                                                    "handler": "toast",
                                                                    "params": {
                                                                        "type": "success",
                                                                        "message": "{{route?.slug ? '$t:sirsoft-board.admin.board.messages.update_success' : '$t:sirsoft-board.admin.board.messages.create_success'}}"
                                                                    }
                                                                },
                                                                {
                                                                    "handler": "openWindow",
                                                                    "condition": "{{!route?.slug}}",
                                                                    "params": {
                                                                        "path": "{{'/admin/boards/' + result.data.slug + '/edit'}}",
                                                                        "target": "_self"
                                                                    }
                                                                }
                                                            ],
                                                            "onError": [
                                                                {
                                                                    "handler": "setState",
                                                                    "params": {
                                                                        "target": "local",
                                                                        "isSaving": false,
                                                                        "errors": "{{error.errors}}"
                                                                    }
                                                                },
                                                                {
                                                                    "handler": "toast",
                                                                    "params": {
                                                                        "type": "error",
                                                                        "message": "{{error.message}}"
                                                                    }
                                                                }
                                                            ]
                                                        }
                                                    ]
                                                }
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    },
    "modals": []
}
