{
    "version": "1.0.0",
    "layout_name": "plugin_settings",
    "permissions": [
        "core.plugins.update"
    ],
    "extends": "_admin_base",
    "meta": {
        "title": "$t:sirsoft-daum_postcode.settings.title",
        "description": "$t:sirsoft-daum_postcode.settings.description"
    },
    "data_sources": [
        {
            "id": "settings",
            "label_key": "$t:sirsoft-daum_postcode.editor.data_source.settings",
            "type": "api",
            "endpoint": "/api/admin/plugins/{{route.identifier}}/settings",
            "method": "GET",
            "auto_fetch": true,
            "auth_required": true,
            "initLocal": "form",
            "refetchOnMount": true
        }
    ],
    "slots": {
        "content": [
            {
                "id": "plugin_settings_content",
                "type": "basic",
                "name": "Div",
                "dataKey": "form",
                "trackChanges": true,
                "props": {
                    "className": "admin-page-content-responsive"
                },
                "children": [
                    {
                        "id": "page_header",
                        "type": "composite",
                        "name": "PageHeader",
                        "props": {
                            "title": "$t:sirsoft-daum_postcode.settings.title",
                            "description": "$t:sirsoft-daum_postcode.settings.description",
                            "backPath": "/admin/plugins",
                            "backLabel": "$t:admin.plugins.back_to_list"
                        }
                    },
                    {
                        "id": "notice_banner",
                        "type": "basic",
                        "name": "Div",
                        "props": {
                            "className": "alert-info"
                        },
                        "children": [
                            {
                                "type": "basic",
                                "name": "Div",
                                "props": {
                                    "className": "flex gap-3"
                                },
                                "children": [
                                    {
                                        "type": "basic",
                                        "name": "Icon",
                                        "props": {
                                            "name": "circle-info",
                                            "className": "w-5 h-5 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5"
                                        }
                                    },
                                    {
                                        "type": "basic",
                                        "name": "P",
                                        "props": {
                                            "className": "text-info-soft"
                                        },
                                        "text": "$t:sirsoft-daum_postcode.settings.notice"
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "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",
                                            "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: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": "grid-3col-responsive"
                                                        },
                                                        "text": "{{message}}"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": "settings_form",
                        "type": "basic",
                        "name": "Div",
                        "props": {
                            "className": "mt-6 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700"
                        },
                        "children": [
                            {
                                "id": "settings_fields",
                                "type": "basic",
                                "name": "Div",
                                "props": {
                                    "className": "p-6 space-y-6"
                                },
                                "children": [
                                    {
                                        "id": "field_display_mode",
                                        "type": "basic",
                                        "name": "Div",
                                        "props": {
                                            "className": "text-error-soft"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-1"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Label",
                                                        "props": {
                                                            "className": "form-label"
                                                        },
                                                        "text": "$t:sirsoft-daum_postcode.settings.fields.display_mode.label"
                                                    },
                                                    {
                                                        "type": "basic",
                                                        "name": "P",
                                                        "props": {
                                                            "className": "form-hint"
                                                        },
                                                        "text": "$t:sirsoft-daum_postcode.settings.fields.display_mode.hint"
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-2"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Select",
                                                        "props": {
                                                            "name": "display_mode",
                                                            "className": "focus:border-transparent"
                                                        },
                                                        "children": [
                                                            {
                                                                "type": "basic",
                                                                "name": "Option",
                                                                "props": {
                                                                    "value": "popup"
                                                                },
                                                                "text": "popup"
                                                            },
                                                            {
                                                                "type": "basic",
                                                                "name": "Option",
                                                                "props": {
                                                                    "value": "layer"
                                                                },
                                                                "text": "layer"
                                                            }
                                                        ]
                                                    }
                                                ]
                                            }
                                        ]
                                    },
                                    {
                                        "id": "field_popup_width",
                                        "type": "basic",
                                        "name": "Div",
                                        "props": {
                                            "className": "text-error-soft"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-1"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Label",
                                                        "props": {
                                                            "className": "form-label"
                                                        },
                                                        "text": "$t:sirsoft-daum_postcode.settings.fields.popup_width.label"
                                                    },
                                                    {
                                                        "type": "basic",
                                                        "name": "P",
                                                        "props": {
                                                            "className": "form-hint"
                                                        },
                                                        "text": "$t:sirsoft-daum_postcode.settings.fields.popup_width.hint"
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-2"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Input",
                                                        "props": {
                                                            "type": "number",
                                                            "name": "popup_width",
                                                            "className": "focus:border-transparent"
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    },
                                    {
                                        "id": "field_popup_height",
                                        "type": "basic",
                                        "name": "Div",
                                        "props": {
                                            "className": "text-error-soft"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-1"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Label",
                                                        "props": {
                                                            "className": "form-label"
                                                        },
                                                        "text": "$t:sirsoft-daum_postcode.settings.fields.popup_height.label"
                                                    },
                                                    {
                                                        "type": "basic",
                                                        "name": "P",
                                                        "props": {
                                                            "className": "form-hint"
                                                        },
                                                        "text": "$t:sirsoft-daum_postcode.settings.fields.popup_height.hint"
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-2"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Input",
                                                        "props": {
                                                            "type": "number",
                                                            "name": "popup_height",
                                                            "className": "focus:border-transparent"
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    },
                                    {
                                        "id": "field_theme_color",
                                        "type": "basic",
                                        "name": "Div",
                                        "props": {
                                            "className": "text-error-soft"
                                        },
                                        "children": [
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-1"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Label",
                                                        "props": {
                                                            "className": "form-label"
                                                        },
                                                        "text": "$t:sirsoft-daum_postcode.settings.fields.theme_color.label"
                                                    },
                                                    {
                                                        "type": "basic",
                                                        "name": "P",
                                                        "props": {
                                                            "className": "form-hint"
                                                        },
                                                        "text": "$t:sirsoft-daum_postcode.settings.fields.theme_color.hint"
                                                    }
                                                ]
                                            },
                                            {
                                                "type": "basic",
                                                "name": "Div",
                                                "props": {
                                                    "className": "lg:col-span-2"
                                                },
                                                "children": [
                                                    {
                                                        "type": "basic",
                                                        "name": "Input",
                                                        "props": {
                                                            "type": "text",
                                                            "name": "theme_color",
                                                            "placeholder": "#1D4ED8",
                                                            "className": "focus:border-transparent"
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": "guide_section",
                        "type": "basic",
                        "name": "Div",
                        "props": {
                            "className": "mt-6 bg-gray-50 dark:bg-gray-800/50 rounded-lg border border-gray-200 dark:border-gray-700 p-6"
                        },
                        "children": [
                            {
                                "type": "basic",
                                "name": "H3",
                                "props": {
                                    "className": "section-heading mb-4"
                                },
                                "text": "$t:sirsoft-daum_postcode.settings.guide.title"
                            },
                            {
                                "type": "basic",
                                "name": "Ol",
                                "props": {
                                    "className": "list-decimal list-inside space-y-3"
                                },
                                "children": [
                                    {
                                        "type": "basic",
                                        "name": "Li",
                                        "props": {
                                            "className": "text-label"
                                        },
                                        "text": "$t:sirsoft-daum_postcode.settings.guide.step1"
                                    },
                                    {
                                        "type": "basic",
                                        "name": "Li",
                                        "props": {
                                            "className": "text-label"
                                        },
                                        "text": "$t:sirsoft-daum_postcode.settings.guide.step2"
                                    },
                                    {
                                        "type": "basic",
                                        "name": "Li",
                                        "props": {
                                            "className": "text-label"
                                        },
                                        "text": "$t:sirsoft-daum_postcode.settings.guide.step3"
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": "footer_buttons",
                        "type": "basic",
                        "name": "Div",
                        "props": {
                            "className": "sticky-footer-buttons"
                        },
                        "children": [
                            {
                                "id": "cancel_button",
                                "type": "basic",
                                "name": "Button",
                                "props": {
                                    "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": {
                                    "disabled": "{{!_local.hasChanges || _local.isSaving}}",
                                    "className": "btn btn-primary flex-center gap-1.5"
                                },
                                "actions": [
                                    {
                                        "type": "click",
                                        "handler": "sequence",
                                        "actions": [
                                            {
                                                "handler": "setState",
                                                "params": {
                                                    "target": "local",
                                                    "isSaving": true,
                                                    "errors": null
                                                }
                                            },
                                            {
                                                "handler": "apiCall",
                                                "auth_required": true,
                                                "target": "/api/admin/plugins/{{route.identifier}}/settings",
                                                "params": {
                                                    "method": "PUT",
                                                    "body": "{{_local.form}}"
                                                },
                                                "onSuccess": [
                                                    {
                                                        "handler": "setState",
                                                        "params": {
                                                            "target": "local",
                                                            "isSaving": false,
                                                            "hasChanges": false
                                                        }
                                                    },
                                                    {
                                                        "handler": "toast",
                                                        "params": {
                                                            "type": "success",
                                                            "message": "$t:admin.plugins.settings.save_success"
                                                        }
                                                    },
                                                    {
                                                        "handler": "refetchDataSource",
                                                        "params": {
                                                            "dataSourceId": "settings"
                                                        }
                                                    }
                                                ],
                                                "onError": [
                                                    {
                                                        "handler": "setState",
                                                        "params": {
                                                            "target": "local",
                                                            "isSaving": false,
                                                            "errors": "{{$error.errors}}"
                                                        }
                                                    },
                                                    {
                                                        "handler": "toast",
                                                        "params": {
                                                            "type": "error",
                                                            "message": "$t:admin.plugins.settings.save_error"
                                                        }
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ],
                                "children": [
                                    {
                                        "type": "basic",
                                        "name": "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"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    },
    "pageConfig": {
        "notice": "$t:sirsoft-daum_postcode.settings.notice",
        "guide": {
            "title": "$t:sirsoft-daum_postcode.settings.guide.title",
            "steps": [
                "$t:sirsoft-daum_postcode.settings.guide.step1",
                "$t:sirsoft-daum_postcode.settings.guide.step2",
                "$t:sirsoft-daum_postcode.settings.guide.step3"
            ]
        }
    },
    "schema": {
        "display_mode": {
            "type": "enum",
            "options": [
                "popup",
                "layer"
            ],
            "default": "layer",
            "label": "$t:sirsoft-daum_postcode.settings.fields.display_mode.label",
            "hint": "$t:sirsoft-daum_postcode.settings.fields.display_mode.hint"
        },
        "popup_width": {
            "type": "integer",
            "default": 500,
            "label": "$t:sirsoft-daum_postcode.settings.fields.popup_width.label",
            "hint": "$t:sirsoft-daum_postcode.settings.fields.popup_width.hint"
        },
        "popup_height": {
            "type": "integer",
            "default": 600,
            "label": "$t:sirsoft-daum_postcode.settings.fields.popup_height.label",
            "hint": "$t:sirsoft-daum_postcode.settings.fields.popup_height.hint"
        },
        "theme_color": {
            "type": "string",
            "default": "#1D4ED8",
            "label": "$t:sirsoft-daum_postcode.settings.fields.theme_color.label",
            "hint": "$t:sirsoft-daum_postcode.settings.fields.theme_color.hint"
        }
    }
}
