import { h } from 'vue';

export interface OfflineImpactBinding {
  id?: number | string;
  title?: string;
}

export interface OfflineImpactCheck {
  canProceed: boolean;
  hasBotBindings: boolean;
  hasPluginBindings: boolean;
  hasWorkflowUsages: boolean;
  botBindings: OfflineImpactBinding[];
  pluginBindings: OfflineImpactBinding[];
  workflowUsages: OfflineImpactBinding[];
  message?: string;
}

function resolveTitle(item: OfflineImpactBinding) {
  return item.title || String(item.id || '');
}

export function joinOfflineImpactTitles(items: OfflineImpactBinding[] = []) {
  return items.map(resolveTitle).filter(Boolean).join('、');
}

export function buildOfflineImpactMessage(
  intro: string,
  items: OfflineImpactBinding[] = [],
  footer?: string,
) {
  return h('div', [
    h('p', intro),
    h(
      'ul',
      items.map((item) => h('li', { key: String(item.id || item.title || '') }, resolveTitle(item))),
    ),
    footer ? h('p', footer) : null,
  ]);
}
