{
  "target_layout": "admin_user_detail",
  "injections": [
    {
      "target_id": "user_detail_tabs",
      "position": "inject_props",
      "props": {
        "tabs": {
          "_append": [
            {
              "id": "ext_marketing",
              "label": "$t:admin.users.form.sections.marketing_consent",
              "iconName": "puzzle-piece"
            }
          ]
        }
      }
    },
    {
      "target_id": "extension_tab_content",
      "position": "append_child",
      "components": [
        {
          "id": "ext_marketing_content",
          "type": "basic",
          "name": "Div",
          "props": {
            "id": "ext_marketing",
            "className": "scroll-mt-32"
          },
          "children": [
            {
              "id": "section_marketing_consent",
              "type": "basic",
              "name": "Div",
              "props": {
                "className": "bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg p-6 mb-6"
              },
              "children": [
                {
                  "type": "basic",
                  "name": "Div",
                  "props": {
                    "className": "flex-between mb-4"
                  },
                  "children": [
                    {
                      "type": "basic",
                      "name": "Div",
                      "props": {
                        "className": "flex-center gap-2"
                      },
                      "children": [
                        {
                          "type": "basic",
                          "name": "Icon",
                          "props": {
                            "name": "bullhorn",
                            "size": "md",
                            "className": "text-secondary"
                          }
                        },
                        {
                          "type": "basic",
                          "name": "H3",
                          "props": {
                            "className": "section-heading"
                          },
                          "text": "$t:admin.users.form.sections.marketing_consent"
                        }
                      ]
                    },
                    {
                      "type": "composite",
                      "name": "ExtensionBadge",
                      "props": {
                        "type": "plugin",
                        "identifier": "sirsoft-marketing",
                        "installedPlugins": "{{_global.installedPlugins}}"
                      }
                    }
                  ]
                },
                {
                  "type": "basic",
                  "name": "Div",
                  "props": {
                    "className": "grid grid-cols-1 gap-4"
                  },
                  "children": [
                    {
                      "type": "basic",
                      "name": "Div",
                      "props": {
                        "className": "space-y-3"
                      },
                      "children": [
                        {
                          "type": "basic",
                          "name": "Label",
                          "if": "{{user?.data?.marketing_consent_enabled === true}}",
                          "props": {
                            "className": "flex-start gap-3"
                          },
                          "children": [
                            {
                              "type": "basic",
                              "name": "Checkbox",
                              "props": {
                                "checked": "{{!!user?.data?.marketing_consent}}",
                                "disabled": true,
                                "className": "mt-0.5 text-blue-600 bg-gray-100 dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded cursor-not-allowed"
                              }
                            },
                            {
                              "type": "basic",
                              "name": "Div",
                              "props": {
                                "className": "flex-1 space-y-1"
                              },
                              "children": [
                                {
                                  "type": "basic",
                                  "name": "Div",
                                  "props": {
                                    "className": "flex-center gap-2 flex-wrap"
                                  },
                                  "children": [
                                    {
                                      "type": "basic",
                                      "name": "Span",
                                      "props": {
                                        "className": "text-heading"
                                      },
                                      "text": "$t:sirsoft-marketing.marketing_consent"
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Span",
                                      "if": "{{user?.data?.marketing_consent_at}}",
                                      "props": {
                                        "className": "inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-green-100 dark:bg-green-900 text-green-700 dark:text-green-400"
                                      },
                                      "text": "{{user?.data?.marketing_consent_at ? '$t:sirsoft-marketing.consent_date_prefix ' + new Date(user.data.marketing_consent_at).toLocaleDateString() : ''}}"
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Span",
                                      "if": "{{!user?.data?.marketing_consent_at}}",
                                      "props": {
                                        "className": "text-tertiary inline-flex items-center px-1.5 py-0.5 rounded font-medium bg-gray-100 dark:bg-gray-700"
                                      },
                                      "text": "$t:sirsoft-marketing.not_agreed"
                                    }
                                  ]
                                },
                                {
                                  "type": "basic",
                                  "name": "Span",
                                  "props": {
                                    "className": "block text-tertiary"
                                  },
                                  "text": "$t:sirsoft-marketing.marketing_consent_desc"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "type": "basic",
                          "name": "Label",
                          "if": "{{user?.data?.marketing_consent_enabled === true}}",
                          "iteration": {
                            "source": "(user?.data?.channels ?? []).filter(ch => ch.enabled !== false)",
                            "item_var": "channel"
                          },
                          "props": {
                            "className": "flex-start gap-3 ml-8"
                          },
                          "children": [
                            {
                              "type": "basic",
                              "name": "Checkbox",
                              "props": {
                                "checked": "{{!!user?.data?.[channel.key]}}",
                                "disabled": true,
                                "className": "mt-0.5 text-blue-600 bg-gray-100 dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded cursor-not-allowed"
                              }
                            },
                            {
                              "type": "basic",
                              "name": "Div",
                              "props": {
                                "className": "flex-1 space-y-1"
                              },
                              "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}}"
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Span",
                                      "if": "{{user?.data?.[channel.key + '_at']}}",
                                      "props": {
                                        "className": "inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-green-100 dark:bg-green-900 text-green-700 dark:text-green-400"
                                      },
                                      "text": "{{user?.data?.[channel.key + '_at'] ? '$t:sirsoft-marketing.consent_date_prefix ' + new Date(user.data[channel.key + '_at']).toLocaleDateString() : ''}}"
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Span",
                                      "if": "{{!user?.data?.[channel.key + '_at']}}",
                                      "props": {
                                        "className": "text-tertiary inline-flex items-center px-1.5 py-0.5 rounded font-medium bg-gray-100 dark:bg-gray-700"
                                      },
                                      "text": "$t:sirsoft-marketing.not_agreed"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "type": "basic",
                      "name": "Div",
                      "props": {
                        "className": "space-y-3"
                      },
                      "children": [
                        {
                          "type": "basic",
                          "name": "Label",
                          "if": "{{user?.data?.third_party_consent_enabled === true}}",
                          "props": {
                            "className": "flex-start gap-3"
                          },
                          "children": [
                            {
                              "type": "basic",
                              "name": "Checkbox",
                              "props": {
                                "checked": "{{!!user?.data?.third_party_consent}}",
                                "disabled": true,
                                "className": "mt-0.5 text-blue-600 bg-gray-100 dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded cursor-not-allowed"
                              }
                            },
                            {
                              "type": "basic",
                              "name": "Div",
                              "props": {
                                "className": "flex-1 space-y-1"
                              },
                              "children": [
                                {
                                  "type": "basic",
                                  "name": "Div",
                                  "props": {
                                    "className": "flex-center gap-2 flex-wrap"
                                  },
                                  "children": [
                                    {
                                      "type": "basic",
                                      "name": "Span",
                                      "props": {
                                        "className": "text-heading"
                                      },
                                      "text": "$t:sirsoft-marketing.third_party_consent"
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Span",
                                      "if": "{{user?.data?.third_party_consent_at}}",
                                      "props": {
                                        "className": "inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-green-100 dark:bg-green-900 text-green-700 dark:text-green-400"
                                      },
                                      "text": "{{user?.data?.third_party_consent_at ? '$t:sirsoft-marketing.consent_date_prefix ' + new Date(user.data.third_party_consent_at).toLocaleDateString() : ''}}"
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Span",
                                      "if": "{{!user?.data?.third_party_consent_at}}",
                                      "props": {
                                        "className": "text-tertiary inline-flex items-center px-1.5 py-0.5 rounded font-medium bg-gray-100 dark:bg-gray-700"
                                      },
                                      "text": "$t:sirsoft-marketing.not_agreed"
                                    }
                                  ]
                                },
                                {
                                  "type": "basic",
                                  "name": "Span",
                                  "props": {
                                    "className": "block text-tertiary"
                                  },
                                  "text": "$t:sirsoft-marketing.third_party_consent_desc"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "type": "basic",
                          "name": "Div",
                          "props": {
                            "className": "space-y-1"
                          },
                          "children": [
                            {
                              "type": "basic",
                              "name": "Label",
                              "if": "{{user?.data?.info_disclosure_enabled === true}}",
                              "props": {
                                "className": "flex-start gap-3"
                              },
                              "children": [
                                {
                                  "type": "basic",
                                  "name": "Checkbox",
                                  "props": {
                                    "checked": "{{!!user?.data?.info_disclosure}}",
                                    "disabled": true,
                                    "className": "mt-0.5 text-blue-600 bg-gray-100 dark:bg-gray-700 border-gray-300 dark:border-gray-600 rounded cursor-not-allowed"
                                  }
                                },
                                {
                                  "type": "basic",
                                  "name": "Div",
                                  "props": {
                                    "className": "flex-1 space-y-1"
                                  },
                                  "children": [
                                    {
                                      "type": "basic",
                                      "name": "Div",
                                      "props": {
                                        "className": "flex-center gap-2 flex-wrap"
                                      },
                                      "children": [
                                        {
                                          "type": "basic",
                                          "name": "Span",
                                          "props": {
                                            "className": "text-heading"
                                          },
                                          "text": "$t:sirsoft-marketing.info_disclosure"
                                        },
                                        {
                                          "type": "basic",
                                          "name": "Span",
                                          "if": "{{user?.data?.info_disclosure_at}}",
                                          "props": {
                                            "className": "inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-green-100 dark:bg-green-900 text-green-700 dark:text-green-400"
                                          },
                                          "text": "{{user?.data?.info_disclosure_at ? '$t:sirsoft-marketing.consent_date_prefix ' + new Date(user.data.info_disclosure_at).toLocaleDateString() : ''}}"
                                        },
                                        {
                                          "type": "basic",
                                          "name": "Span",
                                          "if": "{{!user?.data?.info_disclosure_at}}",
                                          "props": {
                                            "className": "text-tertiary inline-flex items-center px-1.5 py-0.5 rounded font-medium bg-gray-100 dark:bg-gray-700"
                                          },
                                          "text": "$t:sirsoft-marketing.not_agreed"
                                        }
                                      ]
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Span",
                                      "props": {
                                        "className": "block text-tertiary"
                                      },
                                      "text": "$t:sirsoft-marketing.info_disclosure_desc"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "type": "basic",
                              "name": "Span",
                              "props": {
                                "className": "text-hint block ml-8"
                              },
                              "text": "$t:sirsoft-marketing.info_disclosure_warning"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "comment": "동의 이력 테이블",
                  "type": "basic",
                  "name": "Div",
                  "props": {
                    "className": "mt-6 pt-4"
                  },
                  "children": [
                    {
                      "type": "basic",
                      "name": "H3",
                      "props": {
                        "className": "text-primary text-sm font-semibold mb-3"
                      },
                      "text": "$t:admin.users.detail.consent_history"
                    },
                    {
                      "comment": "이력이 없는 경우",
                      "type": "basic",
                      "name": "Div",
                      "if": "{{!user?.data?.consent_histories || user?.data?.consent_histories?.length === 0}}",
                      "props": {
                        "className": "text-label-subtle py-4 text-center"
                      },
                      "text": "$t:sirsoft-marketing.no_consent_history"
                    },
                    {
                      "comment": "이력 테이블",
                      "type": "basic",
                      "name": "Div",
                      "if": "{{user?.data?.consent_histories?.length > 0}}",
                      "props": {
                        "className": "max-h-60 overflow-y-auto overflow-x-auto"
                      },
                      "children": [
                        {
                          "type": "basic",
                          "name": "Table",
                          "props": {
                            "className": "divider-list min-w-full"
                          },
                          "children": [
                            {
                              "type": "basic",
                              "name": "Thead",
                              "props": {
                                "className": "sticky top-0 bg-gray-50 dark:bg-gray-900 z-10"
                              },
                              "children": [
                                {
                                  "type": "basic",
                                  "name": "Tr",
                                  "children": [
                                    {
                                      "type": "basic",
                                      "name": "Th",
                                      "props": {
                                        "className": "text-table-header px-2 py-1.5 text-left"
                                      },
                                      "text": "$t:sirsoft-marketing.history_date"
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Th",
                                      "props": {
                                        "className": "text-table-header px-2 py-1.5 text-left"
                                      },
                                      "text": "$t:sirsoft-marketing.history_channel_key"
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Th",
                                      "props": {
                                        "className": "text-table-header px-2 py-1.5 text-left"
                                      },
                                      "text": "$t:sirsoft-marketing.history_action"
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Th",
                                      "props": {
                                        "className": "text-table-header px-2 py-1.5 text-left"
                                      },
                                      "text": "$t:sirsoft-marketing.history_source"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "type": "basic",
                              "name": "Tbody",
                              "props": {
                                "className": "divider-list"
                              },
                              "children": [
                                {
                                  "type": "basic",
                                  "name": "Tr",
                                  "iteration": {
                                    "source": "{{user?.data?.consent_histories ?? []}}",
                                    "item_var": "history",
                                    "index_var": "histIdx"
                                  },
                                  "children": [
                                    {
                                      "type": "basic",
                                      "name": "Td",
                                      "props": {
                                        "className": "text-primary px-2 py-1.5 text-xs whitespace-nowrap"
                                      },
                                      "text": "{{history?.created_at ?? '-'}}"
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Td",
                                      "props": {
                                        "className": "text-primary px-2 py-1.5 text-xs"
                                      },
                                      "text": "{{history?.channel_key === 'marketing_consent' ? '$t:sirsoft-marketing.marketing_consent' : history?.channel_key === 'third_party_consent' ? '$t:sirsoft-marketing.third_party_consent' : history?.channel_key === 'info_disclosure' ? '$t:sirsoft-marketing.info_disclosure' : ((user?.data?.channels ?? []).find(ch => ch.key === history?.channel_key)?.label ?? history?.channel_key ?? '-')}}"
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Td",
                                      "props": {
                                        "className": "px-2 py-1.5 text-xs"
                                      },
                                      "children": [
                                        {
                                          "type": "basic",
                                          "name": "Span",
                                          "props": {
                                            "className": "{{history?.action === 'granted' ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'}}"
                                          },
                                          "text": "{{history?.action === 'granted' ? '$t:sirsoft-marketing.action_granted' : '$t:sirsoft-marketing.action_revoked'}}"
                                        }
                                      ]
                                    },
                                    {
                                      "type": "basic",
                                      "name": "Td",
                                      "props": {
                                        "className": "px-2 py-1.5 text-tertiary"
                                      },
                                      "text": "{{history?.source === 'register' ? '$t:sirsoft-marketing.source_register' : history?.source === 'admin' ? '$t:sirsoft-marketing.source_admin' : '$t:sirsoft-marketing.source_profile'}}"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "priority": 200
}
