import os

content = '''\'use strict\';

const vscode = require(\'vscode\');
const client = require(\'../api/client\');
const account = require(\'../utils/account\');
const extension = require(\'../extension\');

class HummingbirdProvider {
    constructor(extensionUri, context) {
        this._extensionUri = extensionUri;
        this._context = context;
        this._view = undefined;
    }

    resolveWebviewView(webviewView, context, token) {
        this._view = webviewView;
        webviewView.webview.options = { enableScripts: true, localResourceRoots: [this._extensionUri] };
        webviewView.webview.html = this._getHtmlContent(webviewView.webview);
        webviewView.webview.onDidReceiveMessage(async (message) => { await this._handleMessage(message); });
        client.onOnlineStatusChange((isOnline) => { this._postMessage({ type: \'onlineStatus\', isOnline }); });
    }

    _postMessage(message) { if (this._view) this._view.webview.postMessage(message); }

    async _handleMessage(message) {
        const { type, data } = message;
        try {
            switch (type) {
                case \'verifyKey\': await this._handleVerifyKey(data); break;
                case \'switchAccount\': await this._handleSwitchAccount(data); break;
                case \'getStoredKey\': await this._handleGetStoredKey(); break;
                case \'logout\': await this._handleLogout(); break;
                case \'showMessage\': this._showMessage(data.messageType, data.message); break;
            }
        } catch (error) { this._postMessage({ type: \'error\', error: error.message }); }
    }

    async _handleVerifyKey(data) {
        const result = await client.verifyKey(data.key);
        if (result.success) {
            await this._context.globalState.update(\'hummingbird.key\', data.key);
            if (result.data) {
                await account.writeAccountToLocal(result.data);
                extension.showStatusBar();
                await account.promptRestartCursor(\'账号切换成功，需要重启 Cursor 生效\');
            }
        }
        this._postMessage({ type: \'verifyKeyResult\', result });
    }

    async _handleSwitchAccount(data) {
        const result = await client.switchAccount(data.key);
        if (result.success && result.data) {
            await account.writeAccountToLocal(result.data);
            await account.promptRestartCursor(\'账号切换成功，需要重启 Cursor 生效\');
        }
        this._postMessage({ type: \'switchAccountResult\', result });
    }

    async _handleGetStoredKey() {
        const key = this._context.globalState.get(\'hummingbird.key\');
        this._postMessage({ type: \'storedKeyResult\', key: key || null });
    }

    async _handleLogout() {
        await this._context.globalState.update(\'hummingbird.key\', undefined);
        extension.hideStatusBar();
        this._postMessage({ type: \'logoutResult\', success: true });
    }

    _showMessage(type, msg) {
        if (type === \'error\') vscode.window.showErrorMessage(msg);
        else if (type === \'warning\') vscode.window.showWarningMessage(msg);
        else vscode.window.showInformationMessage(msg);
    }

    _getHtmlContent(webview) {
        return \\\'<!DOCTYPE html><html><head><meta charset="UTF-8"><style>body{padding:16px;font-family:var(--vscode-font-family);color:var(--vscode-foreground)}input{width:100%;padding:8px;margin-bottom:8px;border:1px solid var(--vscode-input-border);background:var(--vscode-input-background);color:var(--vscode-input-foreground);border-radius:4px;box-sizing:border-box}button{width:100%;padding:10px;border:none;border-radius:4px;background:var(--vscode-button-background);color:var(--vscode-button-foreground);cursor:pointer;margin-bottom:8px}button:hover{background:var(--vscode-button-hoverBackground)}button:disabled{opacity:0.5}.secondary{background:var(--vscode-button-secondaryBackground);color:var(--vscode-button-secondaryForeground)}.hidden{display:none}.logo{text-align:center;font-size:18px;font-weight:bold;margin-bottom:16px;color:var(--vscode-textLink-foreground)}.card{padding:12px;background:var(--vscode-editor-background);border:1px solid var(--vscode-panel-border);border-radius:6px;margin-bottom:12px}</style></head><body><div class="logo">蜂鸟CursorPro</div><div id="login"><div style="font-weight:600;margin-bottom:12px">激活蜂鸟CursorPro</div><input type="password" id="key" placeholder="请输入激活码"><button id="verify">验证激活码</button></div><div id="logged" class="hidden"><div class="card"><div id="email">-</div><div style="font-size:11px;opacity:0.7" id="type">-</div><div style="margin-top:8px">剩余额度: <span id="quota">-</span></div><div>到期时间: <span id="expire">-</span></div></div><button id="switch" class="secondary">切换账号</button><button id="logout" class="secondary">退出登录</button></div><script>const vscode=acquireVsCodeApi();const e={key:document.getElementById("key"),verify:document.getElementById("verify"),login:document.getElementById("login"),logged:document.getElementById("logged"),email:document.getElementById("email"),type:document.getElementById("type"),quota:document.getElementById("quota"),expire:document.getElementById("expire"),switch:document.getElementById("switch"),logout:document.getElementById("logout")};e.verify.onclick=()=>{const k=e.key.value.trim();if(!k){vscode.postMessage({type:"showMessage",data:{messageType:"warning",message:"请输入激活码"}});return}e.verify.disabled=true;e.verify.textContent="验证中...";vscode.postMessage({type:"verifyKey",data:{key:k}})};e.switch.onclick=()=>vscode.postMessage({type:"getStoredKey"});e.logout.onclick=()=>vscode.postMessage({type:"logout"});window.onmessage=(ev)=>{const m=ev.data;if(m.type==="verifyKeyResult"){e.verify.disabled=false;e.verify.textContent="验证激活码";if(m.result.success){show(m.result.data);vscode.postMessage({type:"showMessage",data:{messageType:"info",message:"激活成功！"}})}else{vscode.postMessage({type:"showMessage",data:{messageType:"error",message:m.result.error||"验证失败"}})}}else if(m.type==="storedKeyResult"&&m.key){vscode.postMessage({type:"switchAccount",data:{key:m.key}})}else if(m.type==="switchAccountResult"){if(m.result.success){show(m.result.data);vscode.postMessage({type:"showMessage",data:{messageType:"info",message:"切换成功！"}})}else{vscode.postMessage({type:"showMessage",data:{messageType:"error",message:m.result.error||"切换失败"}})}}else if(m.type==="logoutResult"){e.login.classList.remove("hidden");e.logged.classList.add("hidden");e.key.value=""}};function show(d){e.login.classList.add("hidden");e.logged.classList.remove("hidden");if(d){e.email.textContent=d.email||"-";e.type.textContent=d.membership_type||"Free";e.quota.textContent=d.quotaRemaining!==undefined?d.quotaRemaining:"-";e.expire.textContent=d.expireDate?d.expireDate.split(" ")[0]:"-"}}vscode.postMessage({type:"getStoredKey"});</script></body></html>\\\';
    }
}

exports.HummingbirdProvider = HummingbirdProvider;
'''

with open(r"D:\temp\破解\cursorpro-0.4.5\extension\out\webview\provider.js", "w", encoding="utf-8") as f:
    f.write(content)
print("Done")
