<!--
 * @Author: RenXiaoDong
 * @Date: 2025-06-25 10:00:50
-->
<template>
  <div class="account-manage-wrap">
    <div class="filter-wrap bg-#fff border-radius-8px">
      <div class="top flex h-64px px-24px py-10px justify-between items-center">
        <p class="text-18px font-400 lh-26px color-#211F24 title">账户管理</p>
        <div class="flex items-center">
          <a-button type="primary" class="w-139px search-btn" size="medium">
            <template #icon>
              <img :src="icon1" width="16" height="16" />
            </template>
            <template #default>添加投放账号</template>
          </a-button>
        </div>
      </div>
      <FilterBlock @onSearch="handleSearch" @onReset="handleReset" />
    </div>

    <div
      class="tip-row flex justify-between px-16px py-10px w-100% my-12px h-42px"
      :class="{
        normal: isNormalStatus,
        abnormal: isAbnormalStatus,
      }"
    >
      <div class="flex items-center">
        <template v-if="isNormalStatus || isAbnormalStatus">
          <img :src="isNormalStatus ? icon4 : icon5" width="16" height="16" class="mr-8px" />
          <span class="label">
            {{
              isNormalStatus
                ? '太棒啦！所有账号都在正常运行。'
                : `共有 12 个账号存在授权异常，其中：7 个已掉线，5 个已超过 5 天未登录，有掉线风险。`
            }}
          </span>
        </template>
      </div>
      <div>
        <a-space v-if="isAbnormalStatus" class="flex items-center">
          <a-button class="w-96px err-btn" size="mini">
            <template #default>查看异常账号</template>
          </a-button>
        </a-space>
      </div>
    </div>
    <div class="card-wrap">
      <AccountTable :dataSource="dataSource" />
      <div class="pagination-box">
        <a-pagination
          :total="pageInfo.total"
          size="mini"
          show-total
          show-jumper
          show-page-size
          :current="pageInfo.page"
          :page-size="pageInfo.pageSize"
          @change="onPageChange"
          @page-size-change="onPageSizeChange"
        />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

import FilterBlock from './components/filter-block';
import AccountTable from './components/account-table';
import { INITIAL_QUERY } from './constants';

import icon1 from '@/assets/img/media-account/icon-add.png';
import icon4 from '@/assets/img/media-account/icon-success.png';
import icon5 from '@/assets/img/media-account/icon-warn.png';

const tipStatus = ref(2);
const pageInfo = reactive({
  page: 1,
  pageSize: 20,
  total: 100,
});

const query = ref(cloneDeep(INITIAL_QUERY));
const dataSource = ref([]);

const isNormalStatus = computed(() => tipStatus.value === 1);
const isAbnormalStatus = computed(() => tipStatus.value === 2);

onMounted(() => {
  getData();
});

const getData = () => {
  console.log('getData', query.value, pageInfo);
  dataSource.value = new Array(8).fill({
    id: 1,
    name: '全球',
    account_id: 1,
    mobile: 1777777,
    status: 1,
    platform: 0,
    operator: {
      name: '小周',
    },
    group: {
      name: '美团组',
    },
    tags: [
      {
        name: '标签1',
      },
      {
        name: '标签2',
      },
    ],
  });
};
const handleSearch = (newQuery) => {
  query.value = { ...newQuery };
  getData();
};
const handleReset = () => {
  query.value = cloneDeep(INITIAL_QUERY);
  getData();
};

const onPageChange = (current) => {
  pageInfo.page = current;
  getData();
};
const onPageSizeChange = (pageSize) => {
  pageInfo.pageSize = pageSize;
  pageInfo.page = 1;
  getData();
};
</script>

<style scoped lang="scss">
@import './style.scss';
</style>
