<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
  <link rel="icon" href="{{ site_branding.favicon_url }}">
    <title>地址管理 - {{ site_branding.browser_title }}</title>
    <style>
        * { box-sizing: border-box; }
        body { margin: 0; font-family: Arial, "Microsoft YaHei", sans-serif; background: #f5f5f7; font-size: 15px; }
        a { text-decoration: none; color: inherit; }
        .topbar {
            background: #111;
            color: #fff;
            padding: 14px 24px;
            border-bottom: 1px solid rgba(255,255,255,0.06);
        }

        .topbar-inner {
            width: 1200px;
            max-width: calc(100vw - 48px);
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 24px;
        }

        .topbar-brand a {
            color: #fff;
            font-size: 20px;
            font-weight: 800;
            letter-spacing: 0.2px;
            text-decoration: none;
            white-space: nowrap;
        }

        .topbar-links {
            display: flex;
            align-items: center;
            gap: 18px;
            flex-wrap: wrap;
            justify-content: flex-end;
        }

        .topbar-links a,
        .topbar-links span {
            color: #f3f3f3;
            font-size: 14px;
            line-height: 1;
            text-decoration: none;
            white-space: nowrap;
        }

        .topbar-links a:hover {
            color: #ffffff;
        }

        .topbar-user {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            padding: 6px 12px 6px 8px;
            background: rgba(255,255,255,0.08);
            border-radius: 999px;
        }

        .topbar-avatar {
            width: 28px;
            height: 28px;
            border-radius: 50%;
            object-fit: cover;
            background: #eee;
            display: block;
        }

        .container { width: 1100px; margin: 24px auto; }
        .grid { display: grid; grid-template-columns: 420px 1fr; gap: 18px; }

        .card {
            background: white;
            border-radius: 18px;
            padding: 20px 22px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        }

        h1 { margin-top: 0; font-size: 30px; font-weight: 800; }
        h2 { margin-top: 0; font-size: 24px; font-weight: 800; }

        input {
            width: 100%;
            height: 42px;
            padding: 0 12px;
            border: 1px solid #ddd;
            border-radius: 10px;
            margin-bottom: 12px;
            font-size: 14px;
        }

        button {
            height: 42px;
            padding: 0 16px;
            border: none;
            border-radius: 10px;
            cursor: pointer;
            font-size: 14px;
        }

        .btn-dark { background: #111; color: white; }
        .btn-light { background: #f4f4f4; color: #111; }
        .btn-danger { background: #d70018; color: white; }

        .addr {
            border-bottom: 1px solid #f0f0f0;
            padding: 14px 0;
        }
        .addr:last-child { border-bottom: none; }

        .name {
            font-size: 18px;
            font-weight: 700;
            margin-bottom: 6px;
        }

        .muted {
            color: #666;
            font-size: 14px;
            line-height: 1.8;
        }

        .tag {
            display: inline-block;
            background: #111;
            color: white;
            padding: 4px 10px;
            border-radius: 999px;
            font-size: 12px;
            margin-left: 8px;
        }

        .actions {
            margin-top: 10px;
            display: flex;
            gap: 10px;
        }

        .inline {
            display: inline-block;
            margin: 0;
        }

        label.small {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            font-size: 14px;
            color: #444;
        }
    </style>
</head>
<body>
    <div class="topbar">
        <div class="topbar-inner">
            <div class="topbar-brand">
                <a href="/">{{ site_branding.site_name }}</a>
            </div>
            <div class="topbar-links">
                <a href="/">首页</a>
                <a href="/products">全部商品</a>
                {% if session.get("biz_display_name") %}
                    <a href="/cart">购物车</a>
                    <a href="/orders">我的订单</a>
                    <a href="/wallet">我的钱包</a>
                    <a href="/addresses">地址管理</a>
                    <a href="/account">用户主页</a>
                    {% if session.get("biz_is_merchant") %}
                        <a href="/merchant/dashboard">商家后台主页</a>
                    {% else %}
                        <a href="/merchant/apply">商家入驻申请</a>
                    {% endif %}
                    {% if session.get("biz_is_admin") %}
                        <a href="/admin/">管理员后台主页</a>
                    {% endif %}
                    <span class="topbar-user">
    <img class="topbar-avatar"
         src="{{ session.get('biz_avatar_url') or '/uploads/avatars/default-avatar.png' }}"
         alt="头像">
    <span>你好，{{ session.get("biz_display_name") }}</span>
</span>
                    <a href="/logout">退出</a>
                {% else %}
                    <a href="/login">登录</a>
                    <a href="/register">注册</a>
                {% endif %}
            </div>
        </div>
    </div>

    <div class="container">
        <h1>地址管理</h1>
        <div class="grid">
            <div class="card">
                <h2>新增收货地址</h2>
                <form method="post" action="/addresses">
                    <input type="text" name="receiver_name" placeholder="收件人姓名" required>
                    <input type="text" name="receiver_phone" placeholder="收件人电话" required>
                    <input type="text" name="province" placeholder="省份" required>
                    <input type="text" name="city" placeholder="城市" required>
                    <input type="text" name="district" placeholder="区县">
                    <input type="text" name="detail_address" placeholder="详细地址" required>
                    <input type="text" name="postal_code" placeholder="邮编">
                    <label class="small">
                        <input type="checkbox" name="is_default" value="1"> 设为默认地址
                    </label>
                    <div style="margin-top:12px;">
                        <button class="btn-dark" type="submit">保存地址</button>
                    </div>
                </form>
            </div>

            <div class="card">
                <h2>我的地址</h2>
                {% if addresses %}
                    {% for a in addresses %}
                    <div class="addr">
                        <div class="name">
                            {{ a.receiver_name }}
                            {% if a.is_default %}
                                <span class="tag">默认地址</span>
                            {% endif %}
                        </div>
                        <div class="muted">电话：{{ a.receiver_phone }}</div>
                        <div class="muted">
                            {{ a.province }} {{ a.city }} {{ a.district or '' }} {{ a.detail_address }}
                        </div>
                        <div class="muted">邮编：{{ a.postal_code or '暂无' }}</div>
                        <div class="actions">
                            {% if not a.is_default %}
                            <form class="inline" method="post" action="/addresses/{{ a.address_id }}/set-default">
                                <button class="btn-light" type="submit">设为默认</button>
                            </form>
                            {% endif %}
                            <form class="inline" method="post" action="/addresses/{{ a.address_id }}/delete">
                                <button class="btn-danger" type="submit">删除</button>
                            </form>
                        </div>
                    </div>
                    {% endfor %}
                {% else %}
                    <div class="muted">你还没有收货地址，请先新增一个默认地址。</div>
                {% endif %}
            </div>
        </div>
    </div>
</body>
</html>
