{
  "version": "1.0.0",
  "layout_name": "admin_template_list",
  "permissions": [
    "core.templates.read"
  ],
  "extends": "_admin_base",
  "meta": {
    "title": "$t:admin.templates.page_title",
    "description": "$t:admin.templates.page_description"
  },
  "state": {
    "searchQuery": "",
    "showHidden": false
  },
  "transition_overlay": {
    "wait_for": [
      "templates",
      "auto_deactivated_banner"
    ],
    "target": "templates_tab_content",
    "fallback_target": "right_content_area"
  },
  "init_actions": [
    {
      "handler": "setState",
      "params": {
        "target": "global",
        "_local": {
          "searchQuery": "{{query.search || ''}}"
        }
      }
    }
  ],
  "data_sources": [
    {
      "id": "templates",
      "label_key": "$t:editor.data_source.templates",
      "type": "api",
      "endpoint": "/api/admin/templates",
      "method": "GET",
      "auto_fetch": true,
      "auth_required": true,
      "refetchOnMount": true,
      "params": {
        "type": "{{route.type}}",
        "page": "{{query.page}}",
        "per_page": "{{query.per_page || 12}}",
        "search": "{{query.search}}",
        "include_hidden": "{{_local.showHidden ? 1 : 0}}"
      },
      "fallback": {
        "data": {
          "data": [],
          "current_page": 1,
          "last_page": 1,
          "per_page": 12,
          "total": 0
        }
      }
    },
    {
      "id": "auto_deactivated_banner",
      "label_key": "$t:editor.data_source.auto_deactivated_banner",
      "type": "api",
      "endpoint": "/api/admin/extensions/auto-deactivated",
      "method": "GET",
      "auto_fetch": true,
      "auth_required": true,
      "fallback": {
        "data": {
          "items": {
            "plugins": [],
            "modules": [],
            "templates": []
          },
          "current_core_version": ""
        }
      }
    }
  ],
  "slots": {
    "content": [
      {
        "id": "template_list_content",
        "type": "basic",
        "name": "Div",
        "props": {
          "className": "admin-page-content-responsive-fluid"
        },
        "children": [
          {
            "id": "page_header",
            "type": "composite",
            "name": "PageHeader",
            "props": {
              "title": "$t:admin.templates.title",
              "description": "$t:admin.templates.description"
            },
            "children": [
              {
                "id": "refresh_button",
                "type": "composite",
                "name": "IconButton",
                "props": {
                  "iconName": "refresh",
                  "variant": "outline",
                  "size": "md"
                },
                "actions": [
                  {
                    "type": "click",
                    "handler": "refetchDataSource",
                    "params": {
                      "dataSourceId": "templates"
                    }
                  }
                ]
              },
              {
                "id": "check_updates_button",
                "type": "basic",
                "name": "Button",
                "props": {
                  "className": "flex-center gap-2 px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",
                  "disabled": "{{_global.isCheckingTemplateUpdates || templates?.data?.abilities?.can_install !== true}}",
                  "type": "button"
                },
                "responsive": {
                  "portable": {
                    "props": {
                      "className": "hidden"
                    }
                  }
                },
                "actions": [
                  {
                    "type": "click",
                    "handler": "sequence",
                    "actions": [
                      {
                        "handler": "setState",
                        "params": {
                          "target": "global",
                          "isCheckingTemplateUpdates": true
                        }
                      },
                      {
                        "handler": "apiCall",
                        "auth_required": true,
                        "target": "/api/admin/templates/check-updates",
                        "params": {
                          "method": "POST"
                        },
                        "onSuccess": [
                          {
                            "handler": "setState",
                            "params": {
                              "target": "global",
                              "isCheckingTemplateUpdates": false
                            }
                          },
                          {
                            "handler": "refetchDataSource",
                            "params": {
                              "dataSourceId": "templates"
                            }
                          },
                          {
                            "handler": "toast",
                            "params": {
                              "type": "success",
                              "message": "{{response.data?.update_count > 0 ? '$t:admin.templates.check_updates_success|count=' + response.data.update_count : '$t:admin.templates.check_updates_no_updates'}}"
                            }
                          }
                        ],
                        "onError": [
                          {
                            "handler": "setState",
                            "params": {
                              "target": "global",
                              "isCheckingTemplateUpdates": false
                            }
                          },
                          {
                            "handler": "toast",
                            "params": {
                              "type": "error",
                              "message": "{{$error.message}}"
                            }
                          }
                        ]
                      }
                    ]
                  }
                ],
                "children": [
                  {
                    "type": "basic",
                    "name": "Icon",
                    "if": "{{!_global.isCheckingTemplateUpdates}}",
                    "props": {
                      "name": "refresh",
                      "size": "sm"
                    }
                  },
                  {
                    "type": "basic",
                    "name": "Icon",
                    "if": "{{_global.isCheckingTemplateUpdates}}",
                    "props": {
                      "name": "spinner",
                      "size": "sm",
                      "className": "animate-spin"
                    }
                  },
                  {
                    "type": "basic",
                    "name": "Span",
                    "text": "$t:admin.templates.actions.check_updates"
                  }
                ]
              },
              {
                "id": "manual_install_button",
                "type": "basic",
                "name": "Button",
                "props": {
                  "className": "flex-center gap-2 px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",
                  "disabled": "{{templates?.data?.abilities?.can_install !== true}}"
                },
                "responsive": {
                  "portable": {
                    "props": {
                      "className": "hidden"
                    }
                  }
                },
                "actions": [
                  {
                    "type": "click",
                    "handler": "openModal",
                    "target": "template_manual_install_modal"
                  }
                ],
                "children": [
                  {
                    "type": "basic",
                    "name": "Icon",
                    "props": {
                      "name": "upload",
                      "className": "w-5 h-5"
                    }
                  },
                  {
                    "type": "basic",
                    "name": "Span",
                    "text": "$t:admin.templates.manual_install"
                  }
                ]
              },
              {
                "id": "marketplace_button",
                "type": "basic",
                "name": "Button",
                "if": "{{false}}",
                "props": {
                  "className": "flex-center gap-2 px-4 py-2 bg-gray-900 dark:bg-white text-white dark:text-gray-900 rounded-lg hover:bg-gray-800 dark:hover:bg-gray-100 transition-colors"
                },
                "responsive": {
                  "portable": {
                    "props": {
                      "className": "hidden"
                    }
                  }
                },
                "children": [
                  {
                    "type": "basic",
                    "name": "Icon",
                    "props": {
                      "name": "globe",
                      "className": "w-5 h-5"
                    }
                  },
                  {
                    "type": "basic",
                    "name": "Span",
                    "text": "$t:admin.templates.marketplace"
                  }
                ]
              }
            ]
          },
          {
            "id": "mobile_action_buttons",
            "type": "basic",
            "name": "Div",
            "props": {
              "className": "hidden"
            },
            "responsive": {
              "portable": {
                "props": {
                  "className": "flex-center gap-2 -mt-4 mb-4"
                }
              }
            },
            "children": [
              {
                "id": "mobile_manual_install_button",
                "type": "basic",
                "name": "Button",
                "props": {
                  "className": "flex-center flex-1 justify-center gap-2 px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",
                  "disabled": "{{templates?.data?.abilities?.can_install !== true}}"
                },
                "actions": [
                  {
                    "type": "click",
                    "handler": "openModal",
                    "target": "template_manual_install_modal"
                  }
                ],
                "children": [
                  {
                    "type": "basic",
                    "name": "Icon",
                    "props": {
                      "name": "upload",
                      "className": "w-5 h-5"
                    }
                  },
                  {
                    "type": "basic",
                    "name": "Span",
                    "text": "$t:admin.templates.manual_install"
                  }
                ]
              },
              {
                "id": "mobile_marketplace_button",
                "type": "basic",
                "name": "Button",
                "if": "{{false}}",
                "props": {
                  "className": "flex-center flex-1 justify-center gap-2 px-4 py-2 bg-gray-900 dark:bg-white text-white dark:text-gray-900 rounded-lg hover:bg-gray-800 dark:hover:bg-gray-100 transition-colors"
                },
                "children": [
                  {
                    "type": "basic",
                    "name": "Icon",
                    "props": {
                      "name": "globe",
                      "className": "w-5 h-5"
                    }
                  },
                  {
                    "type": "basic",
                    "name": "Span",
                    "text": "$t:admin.templates.marketplace"
                  }
                ]
              }
            ]
          },
          {
            "id": "auto_deactivated_banner_wrapper",
            "type": "basic",
            "name": "Div",
            "if": "{{(auto_deactivated_banner?.data?.items?.templates?.length ?? 0) > 0}}",
            "props": {
              "className": "alert-warning",
              "role": "alert"
            },
            "children": [
              {
                "type": "basic",
                "name": "Div",
                "props": {
                  "className": "flex-start gap-3"
                },
                "children": [
                  {
                    "type": "basic",
                    "name": "Icon",
                    "props": {
                      "name": "exclamation-triangle",
                      "className": "text-amber-600 dark:text-amber-400 mt-0.5 shrink-0"
                    }
                  },
                  {
                    "type": "basic",
                    "name": "Div",
                    "props": {
                      "className": "flex-1 min-w-0"
                    },
                    "children": [
                      {
                        "type": "basic",
                        "name": "P",
                        "props": {
                          "className": "text-sm font-medium text-warning-soft mb-2"
                        },
                        "text": "$t:extensions.banner.title"
                      },
                      {
                        "type": "basic",
                        "name": "Div",
                        "children": [
                          {
                            "type": "basic",
                            "name": "Div",
                            "iteration": {
                              "source": "{{auto_deactivated_banner?.data?.items?.templates ?? []}}",
                              "item_var": "banner_item"
                            },
                            "props": {
                              "className": "flex-between gap-2 text-warning-soft"
                            },
                            "children": [
                              {
                                "type": "basic",
                                "name": "Span",
                                "props": {
                                  "className": "font-mono"
                                },
                                "text": "{{banner_item.identifier}} — $t:defer:extensions.banner.item_required|required={{banner_item.incompatible_required_version ?? ''}}"
                              },
                              {
                                "type": "basic",
                                "name": "Button",
                                "props": {
                                  "type": "button",
                                  "className": "text-warning-soft hover:underline",
                                  "aria-label": "$t:extensions.banner.dismiss"
                                },
                                "actions": [
                                  {
                                    "type": "click",
                                    "handler": "apiCall",
                                    "auth_required": true,
                                    "target": "/api/admin/extensions/template/{{banner_item.identifier}}/dismiss",
                                    "params": {
                                      "method": "POST"
                                    },
                                    "onSuccess": [
                                      {
                                        "handler": "refetchDataSource",
                                        "params": {
                                          "dataSourceId": "auto_deactivated_banner"
                                        }
                                      }
                                    ]
                                  }
                                ],
                                "children": [
                                  {
                                    "type": "basic",
                                    "name": "Icon",
                                    "props": {
                                      "name": "times",
                                      "size": "xs"
                                    }
                                  }
                                ]
                              }
                            ]
                          }
                        ]
                      },
                      {
                        "type": "basic",
                        "name": "Div",
                        "props": {
                          "className": "mt-2"
                        },
                        "children": [
                          {
                            "type": "basic",
                            "name": "Button",
                            "props": {
                              "type": "button",
                              "className": "inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium border border-amber-500 dark:border-amber-400 bg-white dark:bg-gray-800 text-warning-soft hover:bg-amber-50 dark:hover:bg-gray-700 rounded-md focus:outline-none focus:ring-2 focus:ring-amber-500 dark:focus:ring-amber-400 focus:ring-offset-2 transition-colors cursor-pointer"
                            },
                            "actions": [
                              {
                                "type": "click",
                                "handler": "openModal",
                                "target": "core_update_guide_modal"
                              }
                            ],
                            "children": [
                              {
                                "type": "basic",
                                "name": "Icon",
                                "props": {
                                  "name": "arrow-up-circle",
                                  "size": "xs"
                                }
                              },
                              {
                                "type": "basic",
                                "name": "Span",
                                "text": "$t:extensions.banner.guide_link"
                              }
                            ]
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "id": "include_hidden_toggle_wrapper",
            "type": "basic",
            "name": "Div",
            "if": "{{currentUser?.is_super === true}}",
            "props": {
              "className": "flex justify-end mb-3"
            },
            "children": [
              {
                "id": "include_hidden_toggle",
                "type": "basic",
                "name": "Label",
                "props": {
                  "className": "flex-center gap-2 text-body cursor-pointer select-none"
                },
                "children": [
                  {
                    "type": "basic",
                    "name": "Input",
                    "props": {
                      "type": "checkbox",
                      "checked": "{{_local.showHidden === true}}",
                      "className": "w-4 h-4 rounded text-blue-600 dark:text-blue-400 dark:focus:ring-blue-400"
                    },
                    "actions": [
                      {
                        "type": "change",
                        "handler": "setState",
                        "params": {
                          "showHidden": "{{!_local.showHidden}}"
                        }
                      },
                      {
                        "type": "change",
                        "handler": "refetchDataSource",
                        "params": {
                          "dataSourceId": "templates"
                        }
                      }
                    ]
                  },
                  {
                    "type": "basic",
                    "name": "Span",
                    "text": "$t:admin.templates.include_hidden"
                  }
                ]
              }
            ]
          },
          {
            "id": "tab_navigation_wrapper",
            "type": "basic",
            "name": "Div",
            "props": {
              "className": "sticky-tab-nav"
            },
            "children": [
              {
                "id": "tab_navigation",
                "type": "composite",
                "name": "TabNavigation",
                "props": {
                  "tabs": [
                    {
                      "id": "user",
                      "label": "$t:admin.templates.tabs.user"
                    },
                    {
                      "id": "admin",
                      "label": "$t:admin.templates.tabs.admin"
                    }
                  ],
                  "activeTabId": "{{_global.activeTemplateTab || route.type || 'user'}}",
                  "variant": "default"
                },
                "actions": [
                  {
                    "event": "onTabChange",
                    "type": "change",
                    "handler": "sequence",
                    "actions": [
                      {
                        "handler": "setState",
                        "params": {
                          "target": "global",
                          "activeTemplateTab": "{{$args[0]}}"
                        }
                      },
                      {
                        "handler": "navigate",
                        "params": {
                          "path": "/admin/templates/{{$args[0]}}"
                        }
                      },
                      {
                        "handler": "scrollIntoView",
                        "params": {
                          "selector": "#main_content",
                          "behavior": "instant",
                          "block": "start",
                          "waitForElement": true,
                          "timeout": 1000
                        }
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "id": "templates_tab_content",
            "type": "basic",
            "name": "Div",
            "children": [
              {
                "partial": "partials/admin_template_list/_tab_admin.json"
              },
              {
                "partial": "partials/admin_template_list/_tab_user.json"
              }
            ],
            "props": {
              "className": "tab-content"
            }
          }
        ]
      }
    ]
  },
  "modals": [
    {
      "partial": "partials/admin_template_list/_modal_detail.json"
    },
    {
      "partial": "partials/admin_template_list/_modal_install.json"
    },
    {
      "partial": "partials/admin_template_list/_drawer_manifest_preview.json"
    },
    {
      "partial": "partials/admin_template_list/_modal_uninstall.json"
    },
    {
      "partial": "partials/admin_template_list/_modal_activate.json"
    },
    {
      "partial": "partials/admin_template_list/_modal_deactivate.json"
    },
    {
      "partial": "partials/admin_template_list/_modal_manual_install.json"
    },
    {
      "partial": "partials/admin_template_list/_modal_refresh_layouts.json"
    },
    {
      "partial": "partials/admin_template_list/_modal_force_activate.json"
    },
    {
      "partial": "partials/admin_template_list/_modal_update.json"
    },
    {
      "partial": "partials/admin_template_list/_modal_extension_license.json"
    },
    {
      "partial": "partials/admin_settings/_modal_core_update_guide.json"
    }
  ]
}
