{
    "version": "1.0.0",
    "layout_name": "plugin_settings",
    "permissions": [
        "core.plugins.update"
    ],
    "extends": "_admin_base",
    "meta": {
        "title": "$t:sirsoft-marketing.settings.title",
        "description": "$t:sirsoft-marketing.settings.description"
    },
    "data_sources": [
        {
            "id": "settings",
            "label_key": "$t:sirsoft-marketing.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,
            "onSuccess": {
                "handler": "sequence",
                "actions": [
                    {
                        "handler": "setState",
                        "params": {
                            "target": "local",
                            "form.channels": "{{typeof response.data.data.channels === 'string' ? (JSON.parse(response.data.data.channels) ?? []) : (response.data.data.channels ?? [])}}"
                        }
                    },
                    {
                        "handler": "setState",
                        "params": {
                            "target": "global",
                            "channels": "{{typeof response.data.data.channels === 'string' ? (JSON.parse(response.data.data.channels) ?? []) : (response.data.data.channels ?? [])}}"
                        }
                    }
                ]
            }
        }
    ],
    "modals": {
        "channel_edit_modal": {
            "meta": {
                "is_partial": true
            },
            "id": "channel_edit_modal",
            "type": "composite",
            "name": "Modal",
            "props": {
                "title": "$t:sirsoft-marketing.settings.channel_modal.title",
                "width": "min(500px, 95vw)",
                "closeOnBackdropClick": false
            },
            "children": [
                {
                    "type": "basic",
                    "name": "Div",
                    "props": {
                        "className": "row-stack"
                    },
                    "children": [
                        {
                            "type": "basic",
                            "name": "Div",
                            "props": {
                                "className": "flex-between"
                            },
                            "children": [
                                {
                                    "type": "basic",
                                    "name": "Label",
                                    "props": {
                                        "className": "text-body font-medium"
                                    },
                                    "text": "$t:sirsoft-marketing.settings.channel_modal.enabled"
                                },
                                {
                                    "type": "basic",
                                    "name": "Toggle",
                                    "props": {
                                        "checked": "{{_global.editingChannel.enabled}}",
                                        "onChange": ""
                                    },
                                    "actions": [
                                        {
                                            "type": "change",
                                            "handler": "setState",
                                            "params": {
                                                "target": "global",
                                                "editingChannel.enabled": "{{$event.target.checked}}"
                                            }
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "type": "basic",
                            "name": "Div",
                            "children": [
                                {
                                    "type": "basic",
                                    "name": "Label",
                                    "props": {
                                        "className": "block text-xs font-medium text-gray-700 dark:text-gray-300 mb-1"
                                    },
                                    "text": "$t:sirsoft-marketing.settings.channel_modal.key"
                                },
                                {
                                    "type": "basic",
                                    "name": "Input",
                                    "props": {
                                        "type": "text",
                                        "value": "{{_global.editingChannel.key ?? ''}}",
                                        "readOnly": "{{_global.editingChannel.is_system || _global.editingChannel._editing}}",
                                        "placeholder": "$t:sirsoft-marketing.settings.channel_modal.key_placeholder",
                                        "className": "{{_global.editingChannel.is_system || _global.editingChannel._editing ? 'input-readonly w-full' : 'w-full'}}"
                                    },
                                    "actions": [
                                        {
                                            "type": "change",
                                            "handler": "setState",
                                            "params": {
                                                "target": "global",
                                                "editingChannel.key": "{{$event.target.value}}"
                                            }
                                        }
                                    ]
                                },
                                {
                                    "type": "basic",
                                    "name": "P",
                                    "props": {
                                        "className": "form-hint"
                                    },
                                    "text": "$t:sirsoft-marketing.settings.channel_modal.key_hint"
                                }
                            ]
                        },
                        {
                            "type": "basic",
                            "name": "Div",
                            "children": [
                                {
                                    "type": "basic",
                                    "name": "Label",
                                    "props": {
                                        "className": "block text-xs font-medium text-gray-700 dark:text-gray-300 mb-1"
                                    },
                                    "text": "$t:sirsoft-marketing.settings.channel_modal.label_ko"
                                },
                                {
                                    "type": "composite",
                                    "name": "MultilingualInput",
                                    "props": {
                                        "value": "{{_global.editingChannel.label ?? {ko: '', en: ''}}}",
                                        "layout": "tabs",
                                        "name": "channel_label",
                                        "placeholder": "$t:sirsoft-marketing.settings.channel_modal.label_placeholder"
                                    },
                                    "actions": [
                                        {
                                            "event": "onChange",
                                            "handler": "setState",
                                            "params": {
                                                "target": "global",
                                                "editingChannel.label": "{{$args[0]?.target?.value ?? _global.editingChannel.label}}"
                                            }
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "type": "basic",
                            "name": "Div",
                            "children": [
                                {
                                    "type": "basic",
                                    "name": "Label",
                                    "props": {
                                        "className": "block text-xs font-medium text-gray-700 dark:text-gray-300 mb-1"
                                    },
                                    "text": "$t:sirsoft-marketing.settings.channel_modal.page_slug"
                                },
                                {
                                    "type": "basic",
                                    "name": "Input",
                                    "props": {
                                        "type": "text",
                                        "value": "{{_global.editingChannel.page_slug ?? ''}}",
                                        "placeholder": "$t:sirsoft-marketing.settings.channel_modal.page_slug_placeholder",
                                        "className": "w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 focus:border-transparent"
                                    },
                                    "actions": [
                                        {
                                            "type": "change",
                                            "handler": "setState",
                                            "params": {
                                                "target": "global",
                                                "editingChannel.page_slug": "{{$event.target.value}}"
                                            }
                                        }
                                    ]
                                },
                                {
                                    "type": "basic",
                                    "name": "P",
                                    "props": {
                                        "className": "form-hint"
                                    },
                                    "text": "$t:sirsoft-marketing.settings.channel_modal.page_slug_hint"
                                }
                            ]
                        }
                    ]
                },
                {
                    "type": "basic",
                    "name": "Div",
                    "props": {
                        "className": "flex justify-end gap-2 mt-4"
                    },
                    "children": [
                        {
                            "type": "basic",
                            "name": "Button",
                            "props": {
                                "type": "button",
                                "className": "btn btn-secondary"
                            },
                            "actions": [
                                {
                                    "type": "click",
                                    "handler": "closeModal"
                                }
                            ],
                            "children": [
                                {
                                    "type": "basic",
                                    "name": "Span",
                                    "text": "$t:common.cancel"
                                }
                            ]
                        },
                        {
                            "type": "basic",
                            "name": "Button",
                            "props": {
                                "type": "button",
                                "className": "btn btn-primary"
                            },
                            "actions": [
                                {
                                    "type": "click",
                                    "handler": "sequence",
                                    "actions": [
                                        {
                                            "handler": "setState",
                                            "params": {
                                                "target": "global",
                                                "channels": "{{_global.editingChannel._editing ? (_global.channels ?? []).map((ch) => ch.key === _global.editingChannel.key ? { key: _global.editingChannel.key, label: _global.editingChannel.label, page_slug: _global.editingChannel.page_slug, enabled: _global.editingChannel.enabled, is_system: _global.editingChannel.is_system ?? false } : ch) : [...(_global.channels ?? []), { key: _global.editingChannel.key, label: _global.editingChannel.label, page_slug: _global.editingChannel.page_slug, enabled: _global.editingChannel.enabled, is_system: _global.editingChannel.is_system ?? false }]}}"
                                            }
                                        },
                                        {
                                            "handler": "setState",
                                            "params": {
                                                "target": "$parent._local",
                                                "hasChanges": true
                                            }
                                        },
                                        {
                                            "handler": "closeModal"
                                        }
                                    ]
                                }
                            ],
                            "children": [
                                {
                                    "type": "basic",
                                    "name": "Span",
                                    "text": "$t:common.save"
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        "channel_deactivate_modal": {
            "meta": {
                "is_partial": true
            },
            "id": "channel_deactivate_modal",
            "type": "composite",
            "name": "Modal",
            "props": {
                "title": "$t:sirsoft-marketing.settings.channel_deactivate_modal.title",
                "width": "min(400px, 95vw)",
                "closeOnBackdropClick": false
            },
            "children": [
                {
                    "type": "basic",
                    "name": "Div",
                    "props": {
                        "className": "row-stack"
                    },
                    "children": [
                        {
                            "type": "basic",
                            "name": "P",
                            "props": {
                                "className": "text-body"
                            },
                            "text": "$t:sirsoft-marketing.settings.channel_deactivate_modal.message"
                        },
                        {
                            "type": "basic",
                            "name": "Div",
                            "props": {
                                "className": "flex justify-end gap-2 mt-4"
                            },
                            "children": [
                                {
                                    "type": "basic",
                                    "name": "Button",
                                    "props": {
                                        "type": "button",
                                        "className": "btn btn-secondary"
                                    },
                                    "actions": [
                                        {
                                            "type": "click",
                                            "handler": "closeModal"
                                        }
                                    ],
                                    "children": [
                                        {
                                            "type": "basic",
                                            "name": "Span",
                                            "text": "$t:common.cancel"
                                        }
                                    ]
                                },
                                {
                                    "type": "basic",
                                    "name": "Button",
                                    "props": {
                                        "type": "button",
                                        "className": "btn btn-primary"
                                    },
                                    "actions": [
                                        {
                                            "type": "click",
                                            "handler": "sequence",
                                            "actions": [
                                                {
                                                    "handler": "setState",
                                                    "params": {
                                                        "target": "global",
                                                        "channels": "{{[...(_global.channels ?? []), ...((typeof _local.form?.channels === 'string' ? JSON.parse(_local.form.channels) : (_local.form?.channels ?? [])).filter((ch) => ch.key === _global.deletingChannelKey).map((ch) => ({ ...ch, enabled: false })))]}}"
                                                    }
                                                },
                                                {
                                                    "handler": "closeModal"
                                                }
                                            ]
                                        }
                                    ],
                                    "children": [
                                        {
                                            "type": "basic",
                                            "name": "Span",
                                            "text": "$t:sirsoft-marketing.settings.channel_deactivate_modal.confirm"
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    },
    "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:sirsoft-marketing.settings.title",
                            "description": "$t:sirsoft-marketing.settings.description",
                            "backPath": "/admin/plugins",
                            "backLabel": "$t:admin.plugins.back_to_list"
                        }
                    },
                    {
                        "id": "validation_error",
                        "type": "basic",
                        "name": "Div",
                        "if": "{{_local.errors}}",
                        "props": {
                            "className": "alert-danger"
                        },
                        "children": [
                            {
                                "type": "basic",
                                "name": "Div",
                                "props": {
                                    "className": "flex gap-3"
                                },
                                "children": [
                                    {
                                        "type": "basic",
                                        "name": "Icon",
                                        "props": {
                                            "name": "triangle-exclamation",
                                            "size": "md",
                                            "className": "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-soft"
                                                },
                                                "text": "$t:admin.plugins.settings.validation_error"
                                            },
                                            {
                                                "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": "section-heading-md"
                                                        },
                                                        "text": "{{message}}"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": "section_channels_card",
                        "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": "section_channels_header",
                                "type": "basic",
                                "name": "Div",
                                "props": {
                                    "className": "panel-header-row"
                                },
                                "children": [
                                    {
                                        "type": "basic",
                                        "name": "H3",
                                        "props": {
                                            "className": "text-error-strong"
                                        },
                                        "text": "$t:sirsoft-marketing.settings.section.channels"
                                    }
                                ]
                            },
                            {
                                "id": "section_channels_fields",
                                "type": "basic",
                                "name": "Div",
                                "props": {
                                    "className": "divide-y divide-gray-100 dark:divide-gray-700"
                                },
                                "children": [
                                    {
                                        "id": "field_marketing_consent_enabled",
                                        "type": "basic",
                                        "name": "Div",
                                        "props": {
                                            "className": "grid-2col lg:grid-cols-3 items-center px-6 py-4"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-2"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Label",
                                                        "props": {
                                                            "className": "form-label"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.marketing_consent_enabled.label"
                                                    },
                                                    {
                                                        "type": "basic",
                                                        "name": "P",
                                                        "props": {
                                                            "className": "form-hint"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.marketing_consent_enabled.hint"
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-1 flex justify-end"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Toggle",
                                                        "props": {
                                                            "name": "marketing_consent_enabled"
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    },
                                    {
                                        "id": "field_marketing_consent_terms_slug",
                                        "type": "basic",
                                        "name": "Div",
                                        "props": {
                                            "className": "grid-3col-responsive px-6 py-4 bg-gray-100 dark:bg-gray-700"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-2"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Label",
                                                        "props": {
                                                            "className": "form-label"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.marketing_consent_terms_slug.label"
                                                    },
                                                    {
                                                        "type": "basic",
                                                        "name": "P",
                                                        "props": {
                                                            "className": "form-hint"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.marketing_consent_terms_slug.hint"
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-1"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Input",
                                                        "props": {
                                                            "type": "text",
                                                            "name": "marketing_consent_terms_slug",
                                                            "placeholder": "$t:sirsoft-marketing.settings.fields.terms_slug_placeholder",
                                                            "className": "dark:focus:ring-blue-400 focus:border-transparent"
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    },
                                    {
                                        "id": "channels_table_section",
                                        "type": "basic",
                                        "name": "Div",
                                        "props": {
                                            "className": "px-6 py-4"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "flex-between mb-3"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "P",
                                                        "props": {
                                                            "className": "text-body font-medium"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.channels.label"
                                                    },
                                                    {
                                                        "type": "basic",
                                                        "name": "Button",
                                                        "props": {
                                                            "type": "button",
                                                            "className": "flex-center gap-1.5 px-3 py-1.5 bg-blue-600 text-white rounded-lg hover:bg-blue-700 font-medium transition-colors text-sm"
                                                        },
                                                        "actions": [
                                                            {
                                                                "type": "click",
                                                                "handler": "sequence",
                                                                "actions": [
                                                                    {
                                                                        "handler": "setState",
                                                                        "params": {
                                                                            "target": "global",
                                                                            "editingChannel": {
                                                                                "key": "",
                                                                                "label": {
                                                                                    "ko": "",
                                                                                    "en": ""
                                                                                },
                                                                                "page_slug": "",
                                                                                "enabled": true,
                                                                                "is_system": false,
                                                                                "_editing": false
                                                                            }
                                                                        }
                                                                    },
                                                                    {
                                                                        "handler": "openModal",
                                                                        "target": "channel_edit_modal"
                                                                    }
                                                                ]
                                                            }
                                                        ],
                                                        "children": [
                                                            {
                                                                "type": "basic",
                                                                "name": "Icon",
                                                                "props": {
                                                                    "name": "plus",
                                                                    "size": "sm"
                                                                }
                                                            },
                                                            {
                                                                "type": "basic",
                                                                "name": "Span",
                                                                "text": "$t:sirsoft-marketing.settings.channels.add"
                                                            }
                                                        ]
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "basic",
                                                "name": "P",
                                                "props": {
                                                    "className": "text-tertiary mb-3"
                                                },
                                                "text": "$t:sirsoft-marketing.settings.channels.description"
                                            },
                                            {
                                                "id": "channels_table",
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "border border-gray-200 dark:border-gray-600 rounded-lg overflow-hidden"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Div",
                                                        "props": {
                                                            "className": "text-tertiary grid grid-cols-12 gap-2 px-4 py-2 bg-gray-50 dark:bg-gray-700 font-medium uppercase"
                                                        },
                                                        "children": [
                                                            {
                                                                "type": "basic",
                                                                "name": "Div",
                                                                "props": {
                                                                    "className": "col-span-6 sm:col-span-4"
                                                                },
                                                                "text": "$t:sirsoft-marketing.settings.channels.col_label"
                                                            },
                                                            {
                                                                "type": "basic",
                                                                "name": "Div",
                                                                "props": {
                                                                    "className": "hidden sm:block sm:col-span-4"
                                                                },
                                                                "text": "$t:sirsoft-marketing.settings.channels.col_slug"
                                                            },
                                                            {
                                                                "type": "basic",
                                                                "name": "Div",
                                                                "props": {
                                                                    "className": "col-span-4 sm:col-span-2 text-center"
                                                                },
                                                                "text": "$t:sirsoft-marketing.settings.channels.col_enabled"
                                                            },
                                                            {
                                                                "type": "basic",
                                                                "name": "Div",
                                                                "props": {
                                                                    "className": "col-span-2 hidden sm:block"
                                                                }
                                                            }
                                                        ]
                                                    },
                                                    {
                                                        "id": "channels_table_rows",
                                                        "type": "basic",
                                                        "name": "Div",
                                                        "props": {
                                                            "className": "divide-y divide-gray-100 dark:divide-gray-700"
                                                        },
                                                        "iteration": {
                                                            "source": "_global.channels ?? (typeof _local.form.channels === 'string' ? JSON.parse(_local.form.channels) : (_local.form.channels ?? []))",
                                                            "item_var": "channel",
                                                            "index_var": "channelIdx"
                                                        },
                                                        "children": [
                                                            {
                                                                "type": "basic",
                                                                "name": "Div",
                                                                "props": {
                                                                    "className": "grid grid-cols-12 gap-2 px-4 py-3 items-center hover:bg-gray-50 dark:bg-gray-800 dark:hover:bg-gray-700/50"
                                                                },
                                                                "children": [
                                                                    {
                                                                        "type": "basic",
                                                                        "name": "Div",
                                                                        "props": {
                                                                            "className": "col-span-6 sm:col-span-4"
                                                                        },
                                                                        "children": [
                                                                            {
                                                                                "type": "basic",
                                                                                "name": "Div",
                                                                                "props": {
                                                                                    "className": "flex-center gap-2 flex-wrap"
                                                                                },
                                                                                "children": [
                                                                                    {
                                                                                        "type": "basic",
                                                                                        "name": "Span",
                                                                                        "props": {
                                                                                            "className": "text-heading"
                                                                                        },
                                                                                        "text": "{{channel.label.ko ?? channel.key}}"
                                                                                    },
                                                                                    {
                                                                                        "type": "basic",
                                                                                        "name": "Span",
                                                                                        "if": "{{channel.is_system}}",
                                                                                        "props": {
                                                                                            "className": "text-info-soft inline-flex items-center px-1.5 py-0.5 rounded font-medium bg-blue-100 dark:bg-blue-900"
                                                                                        },
                                                                                        "text": "$t:sirsoft-marketing.settings.channels.system_badge"
                                                                                    }
                                                                                ]
                                                                            },
                                                                            {
                                                                                "type": "basic",
                                                                                "name": "Span",
                                                                                "props": {
                                                                                    "className": "text-hint font-mono mt-0.5"
                                                                                },
                                                                                "text": "{{channel.key}}"
                                                                            },
                                                                            {
                                                                                "type": "basic",
                                                                                "name": "Span",
                                                                                "if": "{{!!channel.page_slug}}",
                                                                                "props": {
                                                                                    "className": "block sm:hidden text-xs text-blue-400 dark:text-blue-500 font-mono mt-0.5"
                                                                                },
                                                                                "text": "{{channel.page_slug}}"
                                                                            }
                                                                        ]
                                                                    },
                                                                    {
                                                                        "type": "basic",
                                                                        "name": "Div",
                                                                        "props": {
                                                                            "className": "hidden sm:block sm:col-span-4"
                                                                        },
                                                                        "children": [
                                                                            {
                                                                                "type": "basic",
                                                                                "name": "Span",
                                                                                "props": {
                                                                                    "className": "text-label-subtle font-mono"
                                                                                },
                                                                                "text": "{{channel.page_slug || '-'}}"
                                                                            }
                                                                        ]
                                                                    },
                                                                    {
                                                                        "type": "basic",
                                                                        "name": "Div",
                                                                        "props": {
                                                                            "className": "col-span-4 sm:col-span-2 flex justify-center"
                                                                        },
                                                                        "children": [
                                                                            {
                                                                                "type": "basic",
                                                                                "name": "Toggle",
                                                                                "props": {
                                                                                    "checked": "{{channel.enabled}}",
                                                                                    "size": "sm",
                                                                                    "autoBinding": false
                                                                                },
                                                                                "actions": [
                                                                                    {
                                                                                        "type": "change",
                                                                                        "handler": "sequence",
                                                                                        "actions": [
                                                                                            {
                                                                                                "handler": "setState",
                                                                                                "params": {
                                                                                                    "target": "global",
                                                                                                    "channels": "{{(_global.channels ?? []).map((ch) => ch.key === channel.key ? { ...ch, enabled: $event.target.checked } : ch)}}"
                                                                                                }
                                                                                            },
                                                                                            {
                                                                                                "handler": "setState",
                                                                                                "params": {
                                                                                                    "target": "local",
                                                                                                    "hasChanges": true
                                                                                                }
                                                                                            }
                                                                                        ]
                                                                                    }
                                                                                ]
                                                                            }
                                                                        ]
                                                                    },
                                                                    {
                                                                        "type": "basic",
                                                                        "name": "Div",
                                                                        "props": {
                                                                            "className": "col-span-2 flex justify-end gap-1 sm:gap-2"
                                                                        },
                                                                        "children": [
                                                                            {
                                                                                "type": "basic",
                                                                                "name": "Button",
                                                                                "props": {
                                                                                    "type": "button",
                                                                                    "className": "p-1.5 text-gray-400 dark:text-gray-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-400 rounded transition-colors"
                                                                                },
                                                                                "actions": [
                                                                                    {
                                                                                        "type": "click",
                                                                                        "handler": "sequence",
                                                                                        "actions": [
                                                                                            {
                                                                                                "handler": "setState",
                                                                                                "params": {
                                                                                                    "target": "global",
                                                                                                    "editingChannel": "{{{ ...channel, _editing: true }}}"
                                                                                                }
                                                                                            },
                                                                                            {
                                                                                                "handler": "openModal",
                                                                                                "target": "channel_edit_modal"
                                                                                            }
                                                                                        ]
                                                                                    }
                                                                                ],
                                                                                "children": [
                                                                                    {
                                                                                        "type": "basic",
                                                                                        "name": "Icon",
                                                                                        "props": {
                                                                                            "name": "pen",
                                                                                            "size": "sm"
                                                                                        }
                                                                                    }
                                                                                ]
                                                                            },
                                                                            {
                                                                                "type": "basic",
                                                                                "name": "Button",
                                                                                "if": "{{!channel.is_system}}",
                                                                                "props": {
                                                                                    "type": "button",
                                                                                    "className": "p-1.5 text-gray-400 dark:text-gray-500 hover:text-red-600 dark:text-red-400 dark:hover:text-red-400 rounded transition-colors"
                                                                                },
                                                                                "actions": [
                                                                                    {
                                                                                        "type": "click",
                                                                                        "handler": "sequence",
                                                                                        "actions": [
                                                                                            {
                                                                                                "handler": "setState",
                                                                                                "params": {
                                                                                                    "target": "global",
                                                                                                    "channels": "{{(_global.channels ?? []).filter((ch) => ch.key !== channel.key)}}"
                                                                                                }
                                                                                            },
                                                                                            {
                                                                                                "handler": "setState",
                                                                                                "params": {
                                                                                                    "target": "local",
                                                                                                    "hasChanges": true
                                                                                                }
                                                                                            }
                                                                                        ]
                                                                                    }
                                                                                ],
                                                                                "children": [
                                                                                    {
                                                                                        "type": "basic",
                                                                                        "name": "Icon",
                                                                                        "props": {
                                                                                            "name": "trash",
                                                                                            "size": "sm"
                                                                                        }
                                                                                    }
                                                                                ]
                                                                            }
                                                                        ]
                                                                    }
                                                                ]
                                                            }
                                                        ]
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": "section_legal_card",
                        "type": "basic",
                        "name": "Div",
                        "props": {
                            "className": "mt-4 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700"
                        },
                        "children": [
                            {
                                "id": "section_legal_header",
                                "type": "basic",
                                "name": "Div",
                                "props": {
                                    "className": "panel-header-row"
                                },
                                "children": [
                                    {
                                        "type": "basic",
                                        "name": "H3",
                                        "props": {
                                            "className": "text-error-strong"
                                        },
                                        "text": "$t:sirsoft-marketing.settings.section.legal"
                                    }
                                ]
                            },
                            {
                                "id": "section_legal_fields",
                                "type": "basic",
                                "name": "Div",
                                "props": {
                                    "className": "divide-y divide-gray-100 dark:divide-gray-700"
                                },
                                "children": [
                                    {
                                        "id": "field_third_party_consent_enabled",
                                        "type": "basic",
                                        "name": "Div",
                                        "props": {
                                            "className": "grid-2col lg:grid-cols-3 items-center px-6 py-4"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-2"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Label",
                                                        "props": {
                                                            "className": "form-label"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.third_party_consent_enabled.label"
                                                    },
                                                    {
                                                        "type": "basic",
                                                        "name": "P",
                                                        "props": {
                                                            "className": "form-hint"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.third_party_consent_enabled.hint"
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-1 flex justify-end"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Toggle",
                                                        "props": {
                                                            "name": "third_party_consent_enabled"
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    },
                                    {
                                        "id": "field_third_party_consent_terms_slug",
                                        "type": "basic",
                                        "name": "Div",
                                        "props": {
                                            "className": "grid-3col-responsive px-6 py-4 bg-gray-100 dark:bg-gray-700"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-2"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Label",
                                                        "props": {
                                                            "className": "form-label"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.third_party_consent_terms_slug.label"
                                                    },
                                                    {
                                                        "type": "basic",
                                                        "name": "P",
                                                        "props": {
                                                            "className": "form-hint"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.third_party_consent_terms_slug.hint"
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-1"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Input",
                                                        "props": {
                                                            "type": "text",
                                                            "name": "third_party_consent_terms_slug",
                                                            "placeholder": "$t:sirsoft-marketing.settings.fields.terms_slug_placeholder",
                                                            "className": "dark:focus:ring-blue-400 focus:border-transparent"
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    },
                                    {
                                        "id": "field_info_disclosure_enabled",
                                        "type": "basic",
                                        "name": "Div",
                                        "props": {
                                            "className": "grid-2col lg:grid-cols-3 items-center px-6 py-4"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-2"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Label",
                                                        "props": {
                                                            "className": "form-label"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.info_disclosure_enabled.label"
                                                    },
                                                    {
                                                        "type": "basic",
                                                        "name": "P",
                                                        "props": {
                                                            "className": "form-hint"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.info_disclosure_enabled.hint"
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-1 flex justify-end"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Toggle",
                                                        "props": {
                                                            "name": "info_disclosure_enabled"
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    },
                                    {
                                        "id": "field_info_disclosure_terms_slug",
                                        "type": "basic",
                                        "name": "Div",
                                        "props": {
                                            "className": "grid-3col-responsive px-6 py-4 bg-gray-100 dark:bg-gray-700"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-2"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Label",
                                                        "props": {
                                                            "className": "form-label"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.info_disclosure_terms_slug.label"
                                                    },
                                                    {
                                                        "type": "basic",
                                                        "name": "P",
                                                        "props": {
                                                            "className": "form-hint"
                                                        },
                                                        "text": "$t:sirsoft-marketing.settings.fields.info_disclosure_terms_slug.hint"
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-1"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Input",
                                                        "props": {
                                                            "type": "text",
                                                            "name": "info_disclosure_terms_slug",
                                                            "placeholder": "$t:sirsoft-marketing.settings.fields.terms_slug_placeholder",
                                                            "className": "dark:focus:ring-blue-400 focus:border-transparent"
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "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/plugins/sirsoft-marketing/admin/channels",
                                                "params": {
                                                    "method": "PUT",
                                                    "body": "{{{ channels: _global.channels ?? [] }}}"
                                                },
                                                "onSuccess": [
                                                    {
                                                        "handler": "apiCall",
                                                        "auth_required": true,
                                                        "target": "/api/admin/plugins/{{route.identifier}}/settings",
                                                        "params": {
                                                            "method": "PUT",
                                                            "body": "{{{ marketing_consent_enabled: _local.form.marketing_consent_enabled, marketing_consent_terms_slug: _local.form.marketing_consent_terms_slug, third_party_consent_enabled: _local.form.third_party_consent_enabled, third_party_consent_terms_slug: _local.form.third_party_consent_terms_slug, info_disclosure_enabled: _local.form.info_disclosure_enabled, info_disclosure_terms_slug: _local.form.info_disclosure_terms_slug, channels: _global.channels ?? [] }}}"
                                                        },
                                                        "onSuccess": [
                                                            {
                                                                "handler": "setState",
                                                                "params": {
                                                                    "target": "local",
                                                                    "isSaving": false,
                                                                    "hasChanges": false
                                                                }
                                                            },
                                                            {
                                                                "handler": "refetchDataSource",
                                                                "params": {
                                                                    "dataSourceId": "settings"
                                                                }
                                                            },
                                                            {
                                                                "handler": "toast",
                                                                "params": {
                                                                    "type": "success",
                                                                    "message": "$t:admin.plugins.settings.save_success"
                                                                }
                                                            }
                                                        ],
                                                        "onError": [
                                                            {
                                                                "handler": "setState",
                                                                "params": {
                                                                    "target": "local",
                                                                    "isSaving": false,
                                                                    "errors": "{{error.errors}}"
                                                                }
                                                            },
                                                            {
                                                                "handler": "toast",
                                                                "params": {
                                                                    "type": "error",
                                                                    "message": "$t:admin.plugins.settings.save_error"
                                                                }
                                                            }
                                                        ]
                                                    }
                                                ],
                                                "onError": [
                                                    {
                                                        "handler": "setState",
                                                        "params": {
                                                            "target": "local",
                                                            "isSaving": false
                                                        }
                                                    },
                                                    {
                                                        "handler": "setState",
                                                        "params": {
                                                            "target": "global",
                                                            "deletingChannelKey": "{{error.errors?.channels?.[0] ?? ''}}"
                                                        }
                                                    },
                                                    {
                                                        "handler": "openModal",
                                                        "target": "channel_deactivate_modal"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ],
                                "children": [
                                    {
                                        "type": "basic",
                                        "name": "Icon",
                                        "if": "{{_local.isSaving}}",
                                        "props": {
                                            "name": "spinner",
                                            "className": "spinner-sm"
                                        }
                                    },
                                    {
                                        "type": "basic",
                                        "name": "Span",
                                        "if": "{{!_local.isSaving}}",
                                        "text": "$t:common.save"
                                    },
                                    {
                                        "type": "basic",
                                        "name": "Span",
                                        "if": "{{_local.isSaving}}",
                                        "text": "$t:common.saving"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    }
}
