# Resolved / reopened

Dòng resolved và reopened trong thread của nhân viên, và việc view khách trong inbox bỏ các dòng đó.

## Key rules

- Admin: resolve và reopen hiện thành một dòng centered, chữ #616161, theo nhãn của ActivityBlock; không có avatar và không có bubble nền.
- Admin: view khách trong inbox bỏ mọi activity qua `filterViewerMessages`, nên khách không thấy resolved hay reopened ở đó.
- Admin: activity có text do backend viết thì dùng text đó thay cho nhãn mặc định.

## Use when / Avoid

Dùng khi nhân viên cần thấy vòng đời hội thoại trong thread. Trang này chỉ mô tả inbox; storefront có đường render riêng, chưa được mô tả ở đây.

### Use instead

| Component | Use when |
| --- | --- |
| `ActivityBlock` | Dòng sự kiện hệ thống (resolved, reopened, joined, left, auto-resolved). |
| `filterViewerMessages` | Lọc tin theo người xem; bỏ activity khi người xem là khách. |

## Entry points

| Surface | Owner |
| --- | --- |
| Admin | Block registry map activity sang `ActivityBlock` |
| Admin | WidgetV2Messages gọi `filterViewerMessages` với viewer khách |

## Flow

| Surface | Step | Trigger | UI shown | Component | Copy + i18n key | Timing |
| --- | --- | --- | --- | --- | --- | --- |
| Admin | Hiện sự kiện | Message có activity | Dòng centered với nhãn | ActivityBlock | Conversation resolved / Conversation reopened (literal trong LABELS) | Theo realtime của thread |
| Admin | View khách | Người xem là customer | Activity bị bỏ khỏi danh sách | filterViewerMessages | Không có chữ | Tính khi render |

## Edge cases

| Surface | Case | Behaviour |
| --- | --- | --- |
| Admin | Activity mang text do backend viết | Hiện text đó thay cho nhãn mặc định |
| Admin | Text bắt đầu bằng was | Thêm This conversation phía trước để thành câu đầy đủ |
| Admin | Verb không có trong LABELS | Hiện nguyên verb |

## Live preview

### Standard

Example (Standard) — Thread Standard dùng fixture cục bộ.

```js
import '@avada/chatty-ui/tokens/admin.css';
import {html} from 'lit';
import {IconClose, IconMessage} from '@avada/chatty-ui/elements/icon-glyphs.js';
import '@avada/chatty-ui/elements/surface.js';
import '@avada/chatty-ui/elements/avatar.js';
import '@avada/chatty-ui/elements/badge.js';
import '@avada/chatty-ui/elements/icon-button.js';
import '@avada/chatty-ui/elements/launcher.js';
import '@avada/chatty-ui/elements/button.js';
import {sameGroup} from '@avada/chatty-ui/behaviors/messages.js';

// Reference viewport: 1280 × 900 desktop, 390 × 900 mobile.
const sizes = {
  classic: {width: 400, height: 700},
  'ai-mode': {width: 820, height: 657},
  admin: {width: 527, height: 842}
};
const question = {
  id: 'question',
  senderType: 'customer',
  text: 'Can you help me?',
  createdAt: '2026-01-15T10:00:00Z'
};

/** Viewport-relative sizing survives the initial hidden iframe layout. */
function widgetSize(surface) {
  const mode = new URLSearchParams(location.search).get('mobile');
  const isMobile = mode === null ? innerWidth < 900 : mode === 'true';
  const width = `min(${sizes[surface].width}px, max(0px, 100vw - 40px))`;
  const height = isMobile
    ? `min(${surface === 'admin' ? 848 : 888}px, round(down, calc(${width} * 2.2), 1px))`
    : `${sizes[surface].height}px`;
  return {...sizes[surface], height, mobile: isMobile};
}

/** Local immutable message state with real subscriptions for live previews. */
function fixtureStore(initial) {
  let state = {messages: initial};
  const listeners = new Set();
  return {
    getState: () => state,
    subscribe(listener) {
      listeners.add(listener);
      return () => listeners.delete(listener);
    },
    setMessages(messages) {
      state = {messages};
      listeners.forEach(listener => listener());
    }
  };
}

/** Appends the viewer message without replacing the existing conversation. */
function appendViewer(store, surface, text) {
  const message = {
    id: `viewer-${store.getState().messages.length}`,
    senderType: surface === 'admin' ? 'agent' : 'customer',
    senderMeta: {name: surface === 'admin' ? 'Alex' : 'You'},
    text,
    createdAt: new Date().toISOString()
  };
  store.setMessages([...store.getState().messages, message]);
}

/**
 * One shell owns surface sizing, header, thread and composer for every pattern.
 * @param {string} surface
 * @param {Object} store
 * @param {Object} strings
 * @param {Object} content
 * @param {Function} renderMessage
 * @param {Function} onSend
 * @param {Object} registry
 * @param {boolean} composerHidden
 * @param {string} title
 * @param {Object} headerStart
 * @param {Object} headerActions
 * @param {boolean} sheet
 * @param {string | null} status
 * @returns {Object}
 */
function patternShell({
  surface,
  store,
  strings = {header: 'Store assistant', message: 'Message', send: 'Send'},
  content,
  renderMessage,
  onSend,
  registry,
  title,
  headerStart,
  headerActions,
  status = 'online',
  sheet = false,
  composerHidden = false
}) {
  const size = widgetSize(surface);
  const mobileSheet = sheet && size.mobile;
  if (mobileSheet) {
    size.width = 'none';
    size.height = 'calc(100dvh - 12px)';
  }
  const toggle = (event, closed) => {
    const frame = event.currentTarget.closest('[data-pattern-frame]');
    const panel = frame.querySelector('chatty-surface');
    const launcher = frame.querySelector('[data-pattern-launcher]');
    panel.hidden = closed;
    frame.dataset.closed = String(closed);
    const background = frame.querySelector('[data-sheet-page]');
    if (background) background.inert = !closed && surface === 'ai-mode';
    launcher.hidden = !closed;
    if (closed) {
      launcher.style.insetBlockEnd = `${Math.max(surface === 'ai-mode' ? 40 : 16, frame.getBoundingClientRect().bottom - innerHeight + 20)}px`;
      launcher.focus({preventScroll: true});
    } else {
      const composer = panel.querySelector('chatty-composer');
      const input = !composer.hidden
        ? composer.renderRoot.querySelector('textarea')
        : (panel
            .querySelector('chatty-contact-form:not([hidden])')
            ?.renderRoot.querySelector('chatty-text-field') ??
          panel.querySelector('form chatty-text-field') ??
          panel.querySelector('[data-welcome-invitation]:not([hidden]) chatty-button') ??
          panel
            .querySelector('chatty-pre-chat:not([hidden])')
            ?.renderRoot.querySelector('chatty-button'));
      input?.focus({preventScroll: true});
    }
  };
  const sender = message => {
    const content = renderMessage?.(message) ?? {};
    const messages = store.getState().messages;
    const previous = messages[messages.indexOf(message) - 1];
    if (message.senderType !== 'bot' || sameGroup(message, previous)) return content;
    return {
      ...content,
      sender: html`<span style="display:inline-flex;align-items:center;gap:6px"
        ><chatty-avatar size="sm" label="Assistant">A</chatty-avatar
        >${content.sender ?? message.senderName ?? message.senderMeta?.name ?? 'Assistant'}</span
      >`
    };
  };
  return html`<style>
      [data-pattern-frame] {
        display: flex;
        position: relative;
        justify-content: center;
        inline-size: 100%;
        min-inline-size: 0;
      }
      [data-pattern-frame='classic'] {
        justify-content: flex-end;
      }
      [data-pattern-frame] chatty-surface::part(header) {
        padding: 0;
      }
      [data-pattern-frame='classic'] chatty-surface::part(header),
      [data-pattern-frame='ai-mode'] chatty-surface::part(header) {
        border-bottom-width: 0;
      }
      [data-pattern-frame] [hidden] {
        display: none !important;
      }
      [data-pattern-header] {
        display: flex;
        align-items: center;
        gap: 10px;
        box-sizing: border-box;
        min-inline-size: 0;
        block-size: 52px;
        padding: 0 16px;
      }
      [data-pattern-frame='classic'] [data-pattern-header] {
        block-size: 56px;
        background: var(--chatty-color-accent);
        color: var(--chatty-color-on-accent);
      }
      [data-pattern-frame='classic'] [data-pattern-header] chatty-icon-button {
        --chatty-color-border-focus: var(--chatty-color-on-accent);
      }
      [data-pattern-frame='admin'] [data-pattern-header] {
        block-size: 68px;
        padding: 8px 12px;
      }
      [data-pattern-header] chatty-avatar {
        --chatty-avatar-size: 32px;
      }
      [data-pattern-frame='classic'] [data-pattern-header] chatty-avatar {
        --chatty-avatar-background: #fff;
      }
      [data-pattern-frame='classic'] [data-pattern-header] chatty-avatar::part(base) {
        color: #303030;
        border: 1px solid #767676;
      }
      [data-pattern-actions] {
        display: flex;
        align-items: center;
        gap: 8px;
      }
      [data-pattern-title] {
        flex: 1;
        min-inline-size: 0;
        display: flex;
        flex-direction: column;
      }
      [data-pattern-frame='admin'] [data-pattern-title] {
        gap: 4px;
      }
      [data-pattern-frame='admin'] [data-pattern-title] strong {
        display: flex;
        align-items: center;
        min-block-size: 28px;
        font: var(--p-font-weight-semibold, 650) var(--p-text-heading-md-font-size, 14px) /
          var(--p-text-heading-md-font-line-height, 20px) var(--p-font-family-sans, system-ui);
      }
      [data-pattern-title] strong {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      [data-pattern-header] chatty-icon-button {
        --chatty-icon-button-size: 32px;
        --chatty-icon-button-color: currentColor;
      }
      @media (max-width: 899px), (pointer: coarse) {
        [data-pattern-header] chatty-icon-button {
          --chatty-icon-button-size: 44px;
        }
      }
      [data-pattern-launcher] {
        position: absolute;
        inset-inline-end: 0;
        inset-block-end: 0;
      }
      [data-pattern-frame='ai-mode'] [data-pattern-launcher] {
        inset-inline-end: auto;
        inset-inline-start: 50%;
        transform: translateX(-50%);
      }
      [data-pattern-frame='classic'] [data-pattern-launcher] {
        --chatty-icon-button-size: 56px;
        border-radius: 50%;
        background: var(--chatty-color-accent);
        --chatty-icon-button-color: var(--chatty-color-on-accent);
      }
      [data-sheet-mobile='true'] {
        position: fixed;
        inset: 0;
        inline-size: 100vw;
      }
      [data-sheet-mobile='true'] chatty-surface::part(base) {
        border-radius: 16px 16px 0 0;
      }
      [data-sheet-mobile='true'] chatty-surface {
        position: relative;
        z-index: 2;
        margin-block-start: 12px;
      }
      [data-sheet-page],
      [data-sheet-scrim] {
        position: absolute;
        inset: 0;
        box-sizing: border-box;
      }
      [data-sheet-page] {
        padding: 20px;
        background: var(--chatty-color-bg-surface);
        color: var(--chatty-color-text);
      }
      [data-sheet-scrim] {
        z-index: 1;
        border: 0;
        background: rgb(0 0 0 / 40%);
        animation: sheet-scrim 400ms ease;
      }
      [data-sheet-mobile='true'][data-closed='true'] [data-sheet-scrim] {
        display: none;
      }
      [data-sheet-mobile='true'] [data-pattern-launcher] {
        z-index: 3;
      }
      @keyframes sheet-scrim {
        from {
          opacity: 0;
        }
        to {
          opacity: 1;
        }
      }
      @media (prefers-reduced-motion: reduce) {
        [data-sheet-scrim] {
          animation: none;
        }
      }
    </style>
    <div
      data-pattern-frame=${surface}
      data-sheet-mobile=${String(mobileSheet)}
      data-closed="false"
      style=${`block-size:calc(${size.height} + ${mobileSheet ? 12 : 0}px)`}
    >
      ${
        mobileSheet
          ? html`<div data-sheet-page .inert=${surface === 'ai-mode'}>
                <p>Example storefront</p>
                <chatty-button
                  variant="secondary"
                  type="button"
                  @click=${event => {
                    event.currentTarget.textContent = 'Products opened';
                  }}
                >
                  Browse products
                </chatty-button>
              </div>
              ${surface === 'ai-mode' ? html`<button type="button" data-sheet-scrim tabindex="-1" aria-label="Close chat background" @click=${event => toggle(event, true)}></button>` : ''}`
          : ''
      }
      <chatty-surface
        data-chatty-surface=${surface}
        data-chatty-theme=${surface === 'admin' ? 'light' : (document.documentElement.dataset.chattyTheme ?? document.documentElement.dataset.theme ?? 'light')}
        style=${`inline-size:100%;max-inline-size:${mobileSheet ? 'none' : `${size.width}px`};--chatty-surface-height:${size.height}`}
        .store=${store}
        .registry=${registry ?? null}
        viewer-type=${surface === 'admin' ? 'agent' : 'customer'}
        .selfTypes=${surface === 'admin' ? ['agent', 'bot'] : null}
        .renderMessage=${sender}
      >
        <div slot="header" data-pattern-header>
          ${headerStart ?? ''}
          ${surface === 'admin' ? '' : html`<chatty-avatar label="Store" .status=${status}>S</chatty-avatar>`}
          <span data-pattern-title
            ><strong
              >${title ?? (surface === 'admin' ? 'Customer conversation' : strings.header)}</strong
            >${surface === 'admin' ? html`<chatty-badge size="sm" variant="secondary" style="align-self:flex-start">Customer</chatty-badge>` : status == null ? '' : html`<small data-pattern-status>${status === 'online' ? 'Open' : 'Closed'}</small>`}</span
          >
          <span data-pattern-actions>${headerActions ?? ''}</span>
          ${
            surface === 'admin'
              ? ''
              : html`<chatty-icon-button label="Close panel" @click=${event => toggle(event, true)}
                  >${IconClose()}</chatty-icon-button
                >`
          }
        </div>
        <chatty-thread .strings=${{bot: 'Assistant', ...strings}}></chatty-thread>${content ?? ''}
        <chatty-composer
          slot="footer"
          ?hidden=${composerHidden}
          .label=${strings.message}
          .sendLabel=${strings.send}
          @chatty-send=${event => {
            appendViewer(store, surface, event.detail.text);
            if (onSend) onSend(event.detail.text, event.currentTarget);
            else if (surface !== 'admin')
              store.setMessages([
                ...store.getState().messages,
                {
                  id: `fixture-${store.getState().messages.length}`,
                  senderType: 'bot',
                  text: `You asked: “${event.detail.text}”. I can help with that.`,
                  hasEventTime: false
                }
              ]);
          }}
        ></chatty-composer> </chatty-surface
      >${
        surface === 'admin'
          ? ''
          : surface === 'ai-mode'
            ? html`<chatty-launcher
                data-pattern-launcher
                hidden
                label="Open chat"
                @chatty-open=${event => toggle(event, false)}
                >${IconMessage({size: 20, slot: 'icon'})}Ask a question</chatty-launcher
              >`
            : html`<chatty-icon-button
                data-pattern-launcher
                hidden
                size="lg"
                label="Open chat"
                @click=${event => toggle(event, false)}
                >${IconMessage({size: 24})}</chatty-icon-button
              >`
      }
    </div>`;
}

export function Standard() {
  const store = fixtureStore([
    {...question, senderMeta: {name: 'Sam Taylor'}},
    {
      id: 'resolved',
      senderType: 'system',
      layout: 'centered',
      text: 'Conversation resolved',
      hasEventTime: false
    }
  ]);
  return patternShell({
    surface: 'admin',
    store,
    title: 'Sam Taylor',
    headerActions: html`<chatty-badge
        data-pattern-resolution
        role="status"
        tabindex="-1"
        size="sm"
        variant="secondary"
        >Resolved</chatty-badge
      ><chatty-button
        @click=${event => {
          const button = event.currentTarget;
          button.disabled = true;
          store.setMessages([
            ...store.getState().messages,
            {
              id: 'reopened',
              senderType: 'system',
              layout: 'centered',
              text: 'Conversation reopened',
              hasEventTime: false
            }
          ]);
          const status = button
            .closest('[data-pattern-actions]')
            .querySelector('[data-pattern-resolution]');
          status.textContent = 'Conversation reopened';
          button.remove();
          status.focus({preventScroll: true});
        }}
        >Reopen</chatty-button
      >`
  });
}
```

Reopen giả lập event realtime để append activity, không gọi server. View khách: N/A trong preview (trang Admin). Backend override/unknown verb: N/A trong preview.

### Current

Example (Current (React), being replaced) — ActivityBlock thật với ba activity; styling centered nằm ở MessageFrame nên không có trong specimen.

```jsx
import React from 'react';
import {ActivityBlock} from '@assets/pages/InboxManagement/v2/blocks/ActivityBlock.jsx';

export function Labels() {
  return (
    <div>
      <ActivityBlock block={{activity: 'resolved'}} vm={{}} />
      <br />
      <ActivityBlock block={{activity: 'reopened'}} vm={{}} />
      <br />
      <ActivityBlock block={{activity: 'auto-resolved'}} vm={{}} />
    </div>
  );
}
```

## Admin

### Import / element

#### ActivityBlock

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `ActivityBlock` | @assets/pages/InboxManagement/v2/blocks/ActivityBlock.jsx | .inbox-v2 .chatty-message--centered |

#### Viewer filter

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| filterViewerMessages (hàm, không phải component) | @assets/pages/InboxManagement/v2/helpers/filterViewerMessages.js | .inbox-v2 |

### Anatomy

#### ActivityBlock

| Part | Element |
| --- | --- |
| 1 | Một span chứa nhãn hoặc text của activity. |

#### Viewer filter

| Part | Element |
| --- | --- |
| 1 | Hàm lọc danh sách tin theo người xem; không render UI. |

### Placement / order

#### ActivityBlock

| Context | Order |
| --- | --- |
| Thread | Dòng centered giữa thread, không có gutter. |

#### Viewer filter

| Context | Order |
| --- | --- |
| Not available | Caller quyết định thứ tự. |

### Props

#### ActivityBlock

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `block` | object | activity, text | Caller | activity chọn nhãn; text ghi đè nhãn. |
| `vm` | object | canonical message | Caller | vm.text là nguồn text dự phòng. |

#### Viewer filter

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `viewerType` | string | agent / customer | Caller | customer bỏ activity và telemetry; mọi viewer dedupe theo id. |

### Sizes

#### ActivityBlock

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Dòng activity | — | 2px 12px | — | — | `body-small` | — | Không có size override mobile |

#### Viewer filter

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Not available | — | — | — | — | — | — | — |

### Tokens

#### ActivityBlock

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Chữ | Not available | #616161 | No Dark skin |
| Nền / viền | Not available | transparent; border 0 | No Dark skin |

#### Viewer filter

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Not available | — | — | — |

### States

#### ActivityBlock

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Mặc định | message có activity | Chữ #616161 căn giữa, nền transparent, không viền | Không thêm ARIA |

#### Viewer filter

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Not available | — | — | — |

### Behaviour

#### ActivityBlock

| Interaction | Result |
| --- | --- |
| Chọn chữ | Dùng block.text hoặc vm.text nếu có; không thì nhãn theo activity; không có nhãn thì verb. |

#### Viewer filter

| Interaction | Result |
| --- | --- |
| Activity | Với người xem là customer, bỏ tin có activity (resolved, reopened, assigned). |
| Telemetry | Với customer, bỏ tin isIntent và chatbot-skip-reply. |

### Copy

#### ActivityBlock

| String | i18n key | Where |
| --- | --- | --- |
| Conversation resolved | Không có i18n key (literal) | LABELS.resolved |
| Conversation reopened | Không có i18n key (literal) | LABELS.reopened |
| Conversation auto-resolved | Không có i18n key (literal) | LABELS auto-resolved |

#### Viewer filter

| String | i18n key | Where |
| --- | --- | --- |
| Not available | — | — |

### Source

#### ActivityBlock

| File | Evidence |
| --- | --- |
|  | Nhãn và chọn chữ |
|  | Layout centered |

#### Viewer filter

| File | Evidence |
| --- | --- |
|  | Hàm lọc |
|  | Caller view khách |

## Do / Don't

Do: để nhân viên đọc resolve và reopen ngay trong thread bằng dòng centered.

Don't: bắt buộc khách tạo thread mới vì hội thoại đã resolve; trang này không mô tả thao tác reopen ở server.

## Accessibility

| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
| --- | --- | --- | --- | --- |
| Admin | Span trong bubble centered, không có role riêng | Không focusable | Không có live region riêng | Không khai báo cặp màu trong cell |

