<script setup lang="ts">
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { useFormItem } from 'element-plus';
import BusinessFormDialog from '@/components/custom/business-form-dialog.vue';
import { usePickerSelection } from './business-user-picker/composables/use-picker-selection';
import { useDeptSource } from './business-user-picker/composables/use-dept-source';
import { useChainSource } from './business-user-picker/composables/use-chain-source';
import UserPickerTrigger from './business-user-picker/components/user-picker-trigger.vue';
import IconEpOfficeBuilding from '~icons/ep/office-building';
import IconEpUser from '~icons/ep/user';

defineOptions({ name: 'BusinessUserPicker' });

type Source = 'dept' | 'chain' | 'all';

interface Props {
  userOptions: Api.SystemManage.UserSimple[];
  sources?: Source[];
  multiple?: boolean;
  disabledUserIds?: readonly string[];
  excludeUserIds?: readonly string[];
  disabledLabel?: string;
  placeholder?: string;
  title?: string;
  dialogWidth?: string;
  confirmText?: string;
  triggerSize?: 'default' | 'small' | 'large';
  disabled?: boolean;
}

const props = withDefaults(defineProps<Props>(), {
  sources: () => ['dept', 'chain', 'all'],
  multiple: false,
  disabledUserIds: () => [],
  excludeUserIds: () => [],
  disabledLabel: '',
  placeholder: '请选择用户',
  title: '选择用户',
  dialogWidth: '820px',
  confirmText: '',
  triggerSize: 'default',
  disabled: false
});

interface Emits {
  (e: 'change', value: string | string[] | null): void;
  (e: 'confirm', payload: { userIds: string[] }): void;
  (e: 'cancel'): void;
}
const emit = defineEmits<Emits>();

const model = defineModel<string | string[] | null>({ default: null });
const visible = defineModel<boolean>('visible', { default: false });

const { formItem } = useFormItem();

const source = ref<Source>(props.sources[0] ?? 'all');
const currentNodeId = ref<string | null>(null);
const treeSearch = ref('');
const userSearch = ref('');
const hideAdded = ref(false);

const disabledUserIdSet = computed(() => new Set(props.disabledUserIds.map(String)));
const excludeUserIdSet = computed(() => new Set(props.excludeUserIds.map(String)));

const selection = usePickerSelection(() => ({ multiple: props.multiple }));
const deptSource = useDeptSource(
  () => props.userOptions,
  () => new Set(selection.selectedIds.value),
  () => disabledUserIdSet.value
);
const chainSource = useChainSource(
  () => new Set(selection.selectedIds.value),
  () => disabledUserIdSet.value
);

const showTabs = computed(() => props.sources.length > 1);

const userByIdMap = computed(() => new Map(props.userOptions.map(u => [String(u.id), u])));

const committedIds = computed<string[]>(() => {
  const value = model.value;

  if (Array.isArray(value)) {
    return value.map(String);
  }

  if (typeof value === 'string' && value) {
    return [value];
  }

  return [];
});

const selectedUsers = computed(() =>
  committedIds.value.map(id => userByIdMap.value.get(id)).filter((u): u is Api.SystemManage.UserSimple => Boolean(u))
);

const lockedSelectedIds = computed(() => selection.selectedIds.value.filter(id => disabledUserIdSet.value.has(id)));

const visibleSelectedIds = computed(() => selection.selectedIds.value.slice(0, 4));
const overflowSelectedCount = computed(() => Math.max(0, selection.size.value - 4));
const overflowSelectedIds = computed(() => selection.selectedIds.value.slice(4));
const overflowPopoverVisible = ref(false);
const overflowReferenceEl = ref<HTMLElement | null>(null);

function handleOverflowOutsideClick(e: MouseEvent) {
  if (!overflowPopoverVisible.value) return;
  const target = e.target as HTMLElement | null;
  if (!target) return;
  if (target.closest('.user-picker__overflow-popper')) return;
  if (target.closest('.el-popper')) return;
  if (overflowReferenceEl.value?.contains(target)) return;
  overflowPopoverVisible.value = false;
}

onMounted(() => document.addEventListener('mousedown', handleOverflowOutsideClick, true));
onBeforeUnmount(() => document.removeEventListener('mousedown', handleOverflowOutsideClick, true));

function getUserById(uid: string) {
  return userByIdMap.value.get(uid);
}

function visibleUserIds(): string[] {
  let pool: string[];
  if (source.value === 'all' || !currentNodeId.value) {
    pool = props.userOptions.map(u => String(u.id));
  } else if (source.value === 'dept') {
    const node = deptSource.findNode(deptSource.tree.value, currentNodeId.value);
    pool = node ? deptSource.getNodeUserIds(node) : props.userOptions.map(u => String(u.id));
  } else {
    const node = chainSource.findNode(chainSource.tree.value, currentNodeId.value);
    pool = node ? chainSource.getNodeUserIds(node) : props.userOptions.map(u => String(u.id));
  }
  return pool.filter(id => !excludeUserIdSet.value.has(id));
}

const filteredUserIds = computed(() => {
  let ids = visibleUserIds();
  if (hideAdded.value) ids = ids.filter(id => !disabledUserIdSet.value.has(id));
  const kw = userSearch.value.trim().toLowerCase();
  if (kw) {
    ids = ids.filter(id => {
      const u = getUserById(id);
      if (!u) return false;
      return (
        u.nickname.toLowerCase().includes(kw) ||
        (u.username ?? '').toLowerCase().includes(kw) ||
        (u.deptName ?? '').toLowerCase().includes(kw)
      );
    });
  }
  return ids;
});

async function switchSource(next: Source) {
  if (source.value === next) return;
  source.value = next;
  currentNodeId.value = null;
  treeSearch.value = '';
  if (next === 'dept') await deptSource.ensureLoaded();
  else if (next === 'chain') await chainSource.ensureLoaded();
}

function handleDeptNodeClick(data: Api.SystemManage.DeptSimple) {
  currentNodeId.value = deptSource.nodeKey(data);
}

function handleChainNodeClick(data: Api.SystemManage.UserManagementRelationTreeRespVO) {
  currentNodeId.value = chainSource.nodeKey(data);
}

function toggleDeptCheck(node: Api.SystemManage.DeptSimple) {
  if (!props.multiple) return;
  const ids = deptSource.getNodeUserIds(node).filter(id => !disabledUserIdSet.value.has(id));
  const state = deptSource.getNodeCheckState(node);
  if (state === 'all') selection.removeMany(ids);
  else selection.addMany(ids);
}

function toggleChainCheck(node: Api.SystemManage.UserManagementRelationTreeRespVO) {
  if (!props.multiple) return;
  const ids = chainSource.getNodeUserIds(node).filter(id => !disabledUserIdSet.value.has(id));
  const state = chainSource.getNodeCheckState(node);
  if (state === 'all') selection.removeMany(ids);
  else selection.addMany(ids);
}

function toggleUser(uid: string) {
  if (disabledUserIdSet.value.has(uid)) return;
  selection.toggle(uid);
}

function clearAll() {
  selection.clear(lockedSelectedIds.value);
}

function clearUserFilter() {
  userSearch.value = '';
  hideAdded.value = false;
}

const confirmDisabled = computed(() => {
  if (!props.multiple) return !selection.selectedIds.value.length;
  return selection.size.value === 0;
});

const resolvedConfirmText = computed(() => {
  if (props.confirmText) return props.confirmText;
  if (!props.multiple) return '确定';
  return `确定(${selection.size.value})`;
});

function handleConfirm() {
  if (confirmDisabled.value) return;
  const value = selection.commit();
  model.value = value;
  emit('change', value);
  emit('confirm', { userIds: selection.selectedIds.value });
  visible.value = false;
  nextTick(() => {
    formItem?.validate?.('change').catch(() => {});
  });
}

function handleCancel() {
  emit('cancel');
  visible.value = false;
}

function openDialog() {
  visible.value = true;
}

watch(visible, async value => {
  if (value) {
    treeSearch.value = '';
    userSearch.value = '';
    hideAdded.value = false;
    currentNodeId.value = null;
    source.value = props.sources[0] ?? 'all';
    selection.reset(model.value);
    if (source.value === 'dept') await deptSource.ensureLoaded();
    else if (source.value === 'chain') await chainSource.ensureLoaded();
    await nextTick();
  }
});
</script>

<template>
  <div class="business-user-picker">
    <slot name="trigger" :open="openDialog" :selected-users="selectedUsers" :disabled="disabled">
      <UserPickerTrigger
        :selected-users="selectedUsers"
        :placeholder="placeholder"
        :multiple="multiple"
        :disabled="disabled"
        :size="triggerSize"
        @open="openDialog"
      />
    </slot>

    <BusinessFormDialog
      v-model="visible"
      :title="title"
      preset="lg"
      :width="dialogWidth"
      max-body-height="540px"
      :confirm-disabled="confirmDisabled"
      :confirm-text="resolvedConfirmText"
      @confirm="handleConfirm"
      @cancel="handleCancel"
    >
      <div class="user-picker">
        <div v-if="showTabs" class="user-picker__tabs">
          <button
            v-for="tab in sources"
            :key="tab"
            class="user-picker__tab"
            :class="{ 'is-active': source === tab }"
            type="button"
            @click="switchSource(tab)"
          >
            {{ tab === 'dept' ? '部门' : tab === 'chain' ? '团队' : '全部用户' }}
          </button>
        </div>

        <div class="user-picker__picker" :class="{ 'is-single': source === 'all' }">
          <div v-if="source !== 'all'" class="user-picker__col user-picker__col--tree">
            <div class="user-picker__col-head">{{ source === 'dept' ? '部门' : '团队' }}</div>
            <div class="user-picker__search">
              <ElInput
                v-model="treeSearch"
                size="small"
                clearable
                :placeholder="source === 'dept' ? '搜索部门…' : '搜索成员…'"
              />
            </div>
            <div
              v-loading="source === 'dept' ? deptSource.loading.value : chainSource.loading.value"
              class="user-picker__col-body"
            >
              <ElTree
                v-if="source === 'dept'"
                :data="deptSource.filterByKeyword(treeSearch)"
                :props="deptSource.treeProps.value"
                node-key="id"
                :expand-on-click-node="false"
                :default-expand-all="true"
                :indent="14"
                class="user-picker__tree"
                @node-click="handleDeptNodeClick"
              >
                <template #default="{ data }">
                  <div class="user-picker__node" :class="{ 'is-active': currentNodeId === String(data.id) }">
                    <span
                      v-if="multiple"
                      class="user-picker__node-check"
                      :class="{
                        'is-checked': deptSource.getNodeCheckState(data) === 'all',
                        'is-partial': deptSource.getNodeCheckState(data) === 'partial'
                      }"
                      @click.stop="toggleDeptCheck(data)"
                    />
                    <IconEpOfficeBuilding class="user-picker__node-icon" />
                    <span class="user-picker__node-label">{{ data.name }}</span>
                    <span v-if="deptSource.getMetaText(data)" class="user-picker__node-meta">
                      {{ deptSource.getMetaText(data) }}
                    </span>
                  </div>
                </template>
              </ElTree>
              <ElTree
                v-else
                :data="chainSource.filterByKeyword(treeSearch)"
                :props="chainSource.treeProps.value"
                node-key="userId"
                :expand-on-click-node="false"
                :default-expand-all="true"
                :indent="14"
                class="user-picker__tree"
                @node-click="handleChainNodeClick"
              >
                <template #default="{ data }">
                  <div class="user-picker__node" :class="{ 'is-active': currentNodeId === chainSource.nodeKey(data) }">
                    <span
                      v-if="multiple"
                      class="user-picker__node-check"
                      :class="{
                        'is-checked': chainSource.getNodeCheckState(data) === 'all',
                        'is-partial': chainSource.getNodeCheckState(data) === 'partial'
                      }"
                      @click.stop="toggleChainCheck(data)"
                    />
                    <IconEpUser class="user-picker__node-icon" />
                    <span class="user-picker__node-label">{{ data.userNickname }}</span>
                    <span v-if="chainSource.getMetaText(data)" class="user-picker__node-meta">
                      {{ chainSource.getMetaText(data) }}
                    </span>
                  </div>
                </template>
              </ElTree>
            </div>
          </div>

          <div class="user-picker__col user-picker__col--users">
            <div class="user-picker__col-head user-picker__col-head--user">
              <span>
                候选用户(
                <span>{{ filteredUserIds.length }}</span>
                人)
              </span>
              <label v-if="multiple" class="user-picker__hide-added">
                <ElCheckbox v-model="hideAdded">隐藏已添加</ElCheckbox>
              </label>
            </div>
            <div class="user-picker__search">
              <ElInput
                v-model="userSearch"
                size="small"
                clearable
                :placeholder="source === 'all' ? '搜索用户名 / 部门…' : '搜索用户名…'"
              />
            </div>
            <div class="user-picker__col-body">
              <div v-if="!filteredUserIds.length" class="user-picker__empty">
                该节点下没有匹配用户
                <button
                  v-if="userSearch || hideAdded"
                  type="button"
                  class="user-picker__link user-picker__empty-action"
                  @click="clearUserFilter"
                >
                  清除筛选条件
                </button>
              </div>
              <div
                v-for="uid in filteredUserIds"
                :key="uid"
                class="user-picker__user-row"
                :class="{
                  'is-disabled': disabledUserIdSet.has(uid),
                  'is-selected': !multiple && selection.has(uid)
                }"
                @click="toggleUser(uid)"
              >
                <span v-if="multiple" class="user-picker__node-check" :class="{ 'is-checked': selection.has(uid) }" />
                <span class="user-picker__user-avatar">{{ (getUserById(uid)?.nickname ?? '?').slice(0, 1) }}</span>
                <div class="user-picker__user-main">
                  <div class="user-picker__user-name">{{ getUserById(uid)?.nickname }}</div>
                </div>
                <span v-if="disabledUserIdSet.has(uid) && disabledLabel" class="user-picker__user-tag">
                  {{ disabledLabel }}
                </span>
              </div>
            </div>
          </div>
        </div>

        <div v-if="multiple" class="user-picker__selected">
          <div class="user-picker__selected-head">
            <span>
              已选
              <strong>{{ selection.size.value }}</strong>
              人
            </span>
            <button
              v-if="selection.size.value > lockedSelectedIds.length"
              type="button"
              class="user-picker__link user-picker__link--danger"
              @click="clearAll"
            >
              清空
            </button>
          </div>
          <div v-if="selection.size.value === 0" class="user-picker__selected-empty">从左侧勾选用户后会出现在这里</div>
          <div v-else class="user-picker__chips">
            <span v-for="uid in visibleSelectedIds" :key="uid" class="user-picker__chip">
              <span class="user-picker__chip-name">
                {{ getUserById(uid)?.nickname }}
                <ElTooltip v-if="disabledUserIdSet.has(uid) && disabledLabel" :content="disabledLabel" placement="top">
                  <span class="user-picker__chip-lock">·{{ disabledLabel }}</span>
                </ElTooltip>
              </span>
              <button
                v-if="!disabledUserIdSet.has(uid)"
                type="button"
                class="user-picker__chip-x"
                @click="toggleUser(uid)"
              >
                ×
              </button>
            </span>
            <ElPopover
              v-if="overflowSelectedCount > 0"
              :visible="overflowPopoverVisible"
              placement="top-end"
              :width="360"
              popper-class="user-picker__overflow-popper"
            >
              <template #reference>
                <button
                  ref="overflowReferenceEl"
                  type="button"
                  class="user-picker__chip-more"
                  @click="overflowPopoverVisible = !overflowPopoverVisible"
                >
                  +{{ overflowSelectedCount }} 更多
                </button>
              </template>
              <div class="user-picker__overflow-head">
                <span>
                  另外
                  <strong>{{ overflowSelectedCount }}</strong>
                  人
                </span>
              </div>
              <div class="user-picker__overflow-chips">
                <span v-for="uid in overflowSelectedIds" :key="uid" class="user-picker__chip">
                  <span class="user-picker__chip-name">
                    {{ getUserById(uid)?.nickname }}
                    <ElTooltip
                      v-if="disabledUserIdSet.has(uid) && disabledLabel"
                      :content="disabledLabel"
                      placement="top"
                    >
                      <span class="user-picker__chip-lock">·{{ disabledLabel }}</span>
                    </ElTooltip>
                  </span>
                  <button
                    v-if="!disabledUserIdSet.has(uid)"
                    type="button"
                    class="user-picker__chip-x"
                    @click="toggleUser(uid)"
                  >
                    ×
                  </button>
                </span>
              </div>
            </ElPopover>
          </div>
        </div>
      </div>
    </BusinessFormDialog>
  </div>
</template>

<style scoped>
.business-user-picker {
  display: block;
  width: 100%;
}

/* picker 内容上下贴满，标准 body padding 显得空——仅在含本组件的 dialog 上收紧 */
:deep(.business-form-dialog__body:has(.user-picker)) {
  padding-top: 8px !important;
  padding-bottom: 8px !important;
}

.user-picker {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-picker__tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--el-border-color);
}

.user-picker__tab {
  padding: 6px 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--el-text-color-regular);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.user-picker__tab.is-active {
  color: var(--el-color-primary);
  border-bottom-color: var(--el-color-primary);
  font-weight: 600;
}

.user-picker__picker {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 12px;
  height: min(280px, 44vh);
  min-height: 260px;
}

.user-picker__picker.is-single {
  grid-template-columns: 1fr;
}

.user-picker__col {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--el-border-color);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.user-picker__col-head {
  padding: 6px 10px;
  border-bottom: 1px solid var(--el-border-color);
  background: #fafbfc;
  font-size: 12px;
  color: var(--el-text-color-regular);
}

.user-picker__col-head--user {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-picker__col-body {
  flex: 1;
  overflow-y: auto;
}

.user-picker__search {
  padding: 6px 10px;
  border-bottom: 1px solid var(--el-border-color);
}

.user-picker__tree {
  padding: 4px;
  background: transparent;
}

.user-picker__tree :deep(.el-tree-node__content) {
  height: 32px;
  padding-right: 8px !important;
  border-radius: 4px;
  transition: background-color 0.15s ease;
}

.user-picker__tree :deep(.el-tree-node__content:hover) {
  background: var(--el-fill-color-light);
}

.user-picker__tree :deep(.el-tree-node__expand-icon) {
  padding: 4px;
  color: var(--el-text-color-placeholder);
  font-size: 14px;
}

.user-picker__tree :deep(.el-tree-node__expand-icon.is-leaf) {
  color: transparent;
}

.user-picker__node {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 100%;
  font-size: 13px;
  color: var(--el-text-color-primary);
}

.user-picker__node.is-active {
  color: var(--el-color-primary);
  font-weight: 500;
}

.user-picker__node-check {
  position: relative;
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border: 1px solid var(--el-border-color);
  border-radius: 2px;
  background: var(--el-bg-color);
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease;
}

.user-picker__node-check:hover {
  border-color: var(--el-color-primary);
}

.user-picker__node-check.is-checked {
  background: var(--el-color-primary);
  border-color: var(--el-color-primary);
}

.user-picker__node-check.is-checked::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 4px;
  width: 3px;
  height: 7px;
  border: solid #fff;
  border-width: 0 1px 1px 0;
  transform: rotate(45deg);
}

.user-picker__node-check.is-partial {
  background: var(--el-color-primary);
  border-color: var(--el-color-primary);
}

.user-picker__node-check.is-partial::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 2px;
  margin: -1px 0 0 -4px;
  background: #fff;
  border-radius: 1px;
}

.user-picker__node-icon {
  flex-shrink: 0;
  font-size: 15px;
  color: var(--el-text-color-secondary);
  transition: color 0.15s ease;
}

.user-picker__node.is-active .user-picker__node-icon {
  color: var(--el-color-primary);
}

.user-picker__node-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-picker__node-meta {
  flex-shrink: 0;
  padding-left: 6px;
  font-size: 12px;
  color: var(--el-text-color-placeholder);
  font-variant-numeric: tabular-nums;
}

.user-picker__node.is-active .user-picker__node-meta {
  color: var(--el-color-primary);
  opacity: 0.7;
}

.user-picker__user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  height: 36px;
  border-bottom: 1px solid var(--el-border-color-lighter);
  cursor: pointer;
}

.user-picker__user-row:hover {
  background: var(--el-fill-color);
}

.user-picker__user-row.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.user-picker__user-row.is-disabled:hover {
  background: transparent;
}

.user-picker__user-row.is-selected {
  background: var(--el-color-primary-light-9);
}

.user-picker__user-row.is-selected .user-picker__user-name {
  color: var(--el-color-primary);
  font-weight: 500;
}

.user-picker__user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #c7d2fe, #93c5fd);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-picker__user-main {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.user-picker__user-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-picker__user-tag {
  flex-shrink: 0;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--el-color-warning-light-7);
  color: var(--el-color-warning-dark-2);
}

.user-picker__empty {
  padding: 40px 0;
  text-align: center;
  color: var(--el-text-color-placeholder);
  font-size: 12px;
}

.user-picker__hide-added {
  font-size: 11.5px;
}

.user-picker__empty-action {
  display: block;
  margin: 6px auto 0;
}

.user-picker__selected {
  padding: 8px 12px;
  background: #f8fafc;
  border: 1px solid var(--el-border-color);
  border-radius: 6px;
}

.user-picker__selected-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 11.5px;
  color: var(--el-text-color-regular);
}

.user-picker__selected-head strong {
  color: var(--el-color-primary);
  font-weight: 700;
  font-size: 12.5px;
}

.user-picker__selected-empty {
  display: flex;
  align-items: center;
  min-height: 26px;
  color: var(--el-text-color-placeholder);
  font-size: 11.5px;
}

.user-picker__chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 26px;
}

.user-picker__chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 8px;
  background: #fff;
  border: 1px solid var(--el-border-color-darker);
  border-radius: 999px;
  font-size: 11.5px;
}

.user-picker__chip-name {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.user-picker__chip-lock {
  color: var(--el-color-warning-dark-2);
  font-size: 11px;
}

.user-picker__chip-x {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--el-fill-color);
  color: var(--el-text-color-regular);
  border: none;
  cursor: pointer;
  font-size: 11px;
}

.user-picker__chip-x:hover {
  background: var(--el-color-danger);
  color: #fff;
}

.user-picker__chip-more {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px dashed var(--el-border-color-darker);
  background: transparent;
  color: var(--el-color-primary);
  font-size: 11.5px;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease;
}

.user-picker__chip-more:hover {
  border-color: var(--el-color-primary);
  background: var(--el-color-primary-light-9);
}

.user-picker__overflow-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--el-text-color-regular);
}

.user-picker__overflow-head strong {
  color: var(--el-color-primary);
  font-weight: 700;
}

.user-picker__overflow-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.user-picker__link {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 11.5px;
  padding: 0;
}

.user-picker__link--danger {
  color: var(--el-color-danger);
}

.user-picker__link:hover {
  text-decoration: underline;
}
</style>
