import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{dr as t,fr as n,p as r,pr as i,w as a}from"./control-ui-core-pH6nakZ-.js";import{G as o,J as s,W as c}from"./lit-runtime-BEtFSUCp.js";import{Ht as l,Lt as u,Nt as d,Q as f,Rt as p,Z as m,et as h,qt as g}from"./control-ui-core-Br5DB0Zj.js";function _(e){return g(e===`limited`?`devices.pairing.limitedAccess`:e===`node`?`devices.pairing.nodeAccessSummary`:`devices.pairing.fullAccessSummary`)}function v(e){if(!e.open)return o;let i=e.lifecycle,a=g(`devices.pairing.title`),c=i.phase===`success`?g(`devices.pairing.pairedTitle`):i.phase===`delivery-uncertain`?g(`devices.pairing.deliveryUncertainTitle`):i.phase===`expired`?g(`devices.pairing.expiredTitle`):g(`devices.pairing.subtitle`),l=g(`devices.pairing.copySetupCode`),d=i.phase===`waiting`?i.setup:null,f=d?.gatewayUrls??(d?[d.gatewayUrl]:[]),p=i.access===`node`,v=p?b:y,S=d?`openclaw node run --pair "oc-pair://${d.setupCode}"`:``,C=!!(d&&d.expiresAtMs<=e.nowMs),w=i.phase!==`success`&&i.phase!==`delivery-uncertain`&&i.phase!==`reconciling`&&(i.phase!==`error`||i.source!==`status`),T=i.phase===`selection`||i.phase===`error`&&i.source===`create`;return s`
    <openclaw-modal-dialog label=${a} description=${c} @modal-cancel=${e.onClose}>
      <section class="device-pair-setup">
        <header class="device-pair-setup__header">
          <div class="device-pair-setup__phone" aria-hidden="true">
            ${p?u.server:u.smartphone}
          </div>
          <div>
            <h2>${a}</h2>
            <p>${c}</p>
            ${i.phase!==`success`&&!p?s`<p class="device-pair-setup__get-apps">
                  ${g(`devices.pairing.noApp`)}
                  <button type="button" @click=${e.onGetApps}>
                    ${g(`devices.pairing.getApps`)}
                  </button>
                </p>`:o}
          </div>
          <button
            class="btn btn--icon btn--ghost device-pair-setup__close"
            type="button"
            aria-label=${g(`common.dismiss`)}
            @click=${e.onClose}
          >
            ${u.x}
          </button>
        </header>

        <div class="device-pair-setup__body">
          ${w?s`<fieldset class="device-pair-setup__access" ?disabled=${!T}>
                <legend>${g(`devices.pairing.accessTitle`)}</legend>
                ${x.map(([t,n,r])=>s`<label>
                    <input
                      type="radio"
                      name="device-pair-access"
                      .checked=${i.access===t}
                      @change=${()=>e.onAccessChange(t)}
                    />
                    <span>
                      <strong>${g(n)}</strong>
                      <small>${g(r)}</small>
                    </span>
                  </label>`)}
              </fieldset>`:o}
          ${i.phase===`selection`?s`
                <button class="btn primary" type="button" @click=${e.onRefresh}>
                  ${p?u.server:u.smartphone}
                  ${g(`devices.pairing.generateCode`)}
                </button>
              `:o}
          ${i.phase===`loading`?s`
                <div class="device-pair-setup__loading" role="status" aria-live="polite">
                  <span class="device-pair-setup__spinner" aria-hidden="true"></span>
                  <span>${g(`devices.pairing.generating`)}</span>
                </div>
              `:o}
          ${i.phase===`reconciling`?s`
                <div class="device-pair-setup__loading" role="status" aria-live="polite">
                  <span class="device-pair-setup__spinner" aria-hidden="true"></span>
                  <span>${g(`common.loading`)}</span>
                </div>
              `:o}
          ${i.phase===`error`?s`
                <div class="callout danger device-pair-setup__error" role="alert">
                  <strong
                    >${g(i.source===`status`?`devices.pairing.statusFailed`:`devices.pairing.failed`)}</strong
                  >
                  <span>${i.message}</span>
                </div>
                <button class="btn primary" type="button" @click=${e.onRefresh}>
                  ${u.refresh} ${g(`common.reload`)}
                </button>
              `:o}
          ${d?s`
                ${p?s`<div class="device-pair-setup__command">
                      ${C?o:s`<div class="login-gate__command">
                            <code>${S}</code>
                            ${h(S,g(`connection.help.copyCommand`))}
                          </div>`}
                      <p class="device-pair-setup__waiting" role="timer" aria-live="off">
                        ${C?g(`devices.pairing.nodeExpired`):g(`devices.pairing.nodeExpiresIn`,{time:r(d.expiresAtMs,e.nowMs)})}
                      </p>
                    </div>`:s`<div class="device-pair-setup__qr-frame">
                      ${d.qrDataUrl?s`<img
                            class="device-pair-setup__qr"
                            src=${d.qrDataUrl}
                            alt=${g(`devices.pairing.qrAlt`)}
                            width="360"
                            height="360"
                            draggable="false"
                          />`:s`<div class="device-pair-setup__qr-unavailable">
                            ${g(`devices.pairing.qrUnavailable`)}
                          </div>`}
                    </div>`}

                <div class="device-pair-setup__meta">
                  <span class="settings-status settings-status--accent">
                    <span class="settings-status__dot"></span>
                    ${d.auth}
                  </span>
                  <div class="device-pair-setup__gateways">
                    ${f.map(e=>s`
                        <span class="device-pair-setup__gateway" title=${e}
                          >${e}</span
                        >
                      `)}
                  </div>
                </div>

                ${d.accessDowngraded?s`
                      <div class="callout warn device-pair-setup__access-warning" role="status">
                        <strong>${g(`devices.pairing.transportLimitedTitle`)}</strong>
                        <span>${g(`devices.pairing.transportLimitedHint`)}</span>
                      </div>
                    `:o}

                <div class="device-pair-setup__actions">
                  ${p?o:s`<button
                        class="btn primary"
                        type="button"
                        @click=${e=>void m(e,d.setupCode,l)}
                      >
                        ${u.copy} <span data-copy-label>${l}</span>
                      </button>`}
                  <button class="btn" type="button" @click=${e.onRefresh}>
                    ${u.refresh} ${g(`devices.pairing.newCode`)}
                  </button>
                </div>

                <details class="device-pair-setup__fallback">
                  <summary>${g(`devices.pairing.showSetupCode`)}</summary>
                  <code>${d.setupCode}</code>
                </details>

                ${e.pendingCount>0?s`
                      <div class="callout warn device-pair-setup__pending">
                        <span>
                          ${g(`devices.pairing.pending`,{count:String(e.pendingCount)})}
                        </span>
                        <button class="btn btn--sm" @click=${e.onManageDevices}>
                          ${g(`devices.pairing.review`)}
                        </button>
                      </div>
                    `:s`<p class="device-pair-setup__waiting">
                      ${g(p?`devices.pairing.nodeWaiting`:`devices.pairing.waiting`)}
                    </p>`}
              `:o}
          ${i.phase===`success`?s`<div class="device-pair-setup__state" role="status" aria-live="polite">
                <div
                  class="device-pair-setup__state-icon device-pair-setup__state-icon--success"
                  aria-hidden="true"
                >
                  ${u.badgeCheck}
                </div>
                <h3>${i.deviceName??g(`devices.pairing.pairedTitle`)}</h3>
                <p>
                  ${i.deviceName?s`${g(`devices.pairing.pairedTitle`)} <span aria-hidden="true">·</span> `:o}${_(i.access)}
                </p>
                <button class="btn primary" type="button" @click=${e.onClose}>
                  ${g(`devices.pairing.done`)}
                </button>
              </div>`:o}
          ${i.phase===`delivery-uncertain`?s`<div class="device-pair-setup__state" role="alert">
                <div class="device-pair-setup__state-icon" aria-hidden="true">
                  ${u.alertTriangle}
                </div>
                <h3>${g(`devices.pairing.deliveryUncertainTitle`)}</h3>
                <p>${g(`devices.pairing.deliveryUncertainHint`)}</p>
                <div class="device-pair-setup__actions">
                  <button class="btn primary" type="button" @click=${e.onRefresh}>
                    ${u.refresh} ${g(`devices.pairing.generateNewCode`)}
                  </button>
                </div>
              </div>`:o}
          ${i.phase===`expired`?s`<div class="device-pair-setup__state" role="status" aria-live="polite">
                <div class="device-pair-setup__state-icon" aria-hidden="true">${u.refresh}</div>
                <h3>${g(`devices.pairing.expiredTitle`)}</h3>
                <button class="btn primary" type="button" @click=${e.onRefresh}>
                  ${u.refresh} ${g(`devices.pairing.generateNewCode`)}
                </button>
              </div>`:o}
        </div>

        <footer class="device-pair-setup__footer">
          <a
            href=${v}
            target=${t}
            rel=${n()}
            aria-label=${g(`devices.pairing.helpNewTab`)}
          >
            <span>${g(`devices.pairing.help`)}</span>
            <span class="device-pair-setup__external-icon" aria-hidden="true"
              >${u.externalLink}</span
            >
          </a>
          <button class="btn btn--ghost" type="button" @click=${e.onManageDevices}>
            ${g(`devices.pairing.manageDevices`)}
          </button>
        </footer>
      </section>
    </openclaw-modal-dialog>
  `}var y,b,x;function S(){return(S=e((()=>{c(),f(),p(),d(),l(),i(),a(),y=`https://docs.openclaw.ai/channels/pairing#pair-from-the-control-ui-recommended`,b=`https://docs.openclaw.ai/gateway/pairing#one-paste-node-pairing`,x=[[`full`,`devices.pairing.fullAccess`,`devices.pairing.fullAccessHint`],[`limited`,`devices.pairing.limitedAccess`,`devices.pairing.limitedAccessHint`],[`node`,`devices.pairing.nodeAccess`,`devices.pairing.nodeAccessHint`]]})))()}S();export{v as renderDevicePairSetup};
//# sourceMappingURL=view-pairing.runtime-Dv0qtb6U.js.map