"use strict";
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var common_vendor = require("../../common/vendor.js");
var tianjia = require("../../tianjia.js");
var kongshuju = require("../../kongshuju.js");
var config_index = require("../../config/index.js");
var api_index = require("../../api/index.js");
require("../../utils/request.js");
const _sfc_main = {
  setup(__props) {
    const openMenu = common_vendor.ref(false);
    const finished = common_vendor.ref(false);
    const rolesList = common_vendor.ref([]);
    const getRoleList = () => {
      api_index.getAllRoles().then(({ status, data }) => {
        if (Number(status) === 200 && Array.isArray(data)) {
          rolesList.value = data;
        }
      }).finally(getList);
    };
    const list = common_vendor.ref([]);
    const getList = () => {
      api_index.getListOfCommunity({
        start_time: common_vendor.hooks().subtract(7, "days").startOf().format("YYYY-MM-DD HH:mm:ss"),
        stop_time: common_vendor.hooks().endOf().format("YYYY-MM-DD HH:mm:ss"),
        role_id: curRoleId.value
      }).then(({ status, data }) => {
        if (Number(status) === 200 && Array.isArray(data.post_list)) {
          const array = data.post_list.map((item) => {
            var _a;
            const content = JSON.parse(item.content);
            const cover = (_a = content == null ? void 0 : content.images) == null ? void 0 : _a[0];
            return __spreadProps(__spreadValues({}, item), {
              cover
            });
          });
          list.value = array;
        }
      }).finally(() => {
        finished.value = true;
      });
    };
    const curRoleId = common_vendor.ref("");
    const curRoleName = common_vendor.computed$1(() => {
      const roleItem = rolesList.value.find((item) => item.role_id === curRoleId.value);
      if (roleItem) {
        return roleItem.role_name;
      }
      return "\u840C\u4E3B\u4EEC";
    });
    const onRoleChange = (item) => {
      if (item) {
        curRoleId.value = item.role_id;
      } else {
        curRoleId.value = "";
      }
      openMenu.value = false;
      getList();
    };
    const toSubmitCommunity = () => {
      common_vendor.index.navigateTo({
        url: "/pages/community/release"
      });
    };
    const toDetail = (item) => {
      common_vendor.index.navigateTo({
        url: `/pages/community/detail?id=${item.post_id}`
      });
    };
    common_vendor.onShow(getRoleList);
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.t(common_vendor.unref(curRoleName)),
        b: common_vendor.n(openMenu.value ? "open" : ""),
        c: common_vendor.o(($event) => openMenu.value = !openMenu.value),
        d: common_vendor.n(curRoleId.value === "" ? "active" : ""),
        e: common_vendor.o(($event) => onRoleChange(null)),
        f: common_vendor.f(rolesList.value, (item, k0, i0) => {
          return {
            a: `${common_vendor.unref(config_index.filePrefix)}${item.avatar_id}`,
            b: common_vendor.t(item.role_name),
            c: item.role_id,
            d: common_vendor.n(curRoleId.value === item.role_id ? "active" : ""),
            e: common_vendor.o(($event) => onRoleChange(item), item.role_id)
          };
        }),
        g: common_vendor.n(openMenu.value ? "open" : ""),
        h: tianjia._imports_0,
        i: common_vendor.o(toSubmitCommunity),
        j: finished.value && list.value.length === 0
      }, finished.value && list.value.length === 0 ? {
        k: kongshuju._imports_1
      } : finished.value && list.value.length > 0 ? {
        m: common_vendor.f(list.value, (item, index, i0) => {
          return common_vendor.e({
            a: `${common_vendor.unref(config_index.filePrefix)}${item.cover}`,
            b: common_vendor.t(item.title),
            c: item.user_avatar_id
          }, item.user_avatar_id ? {
            d: `${common_vendor.unref(config_index.filePrefix)}${item.user_avatar_id}`
          } : {}, {
            e: common_vendor.t(item.username),
            f: item.is_like
          }, item.is_like ? {} : {}, {
            g: common_vendor.t(item.like_count),
            h: index,
            i: common_vendor.o(($event) => toDetail(item))
          });
        })
      } : {}, {
        l: finished.value && list.value.length > 0
      });
    };
  }
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-5fb47dc3"], ["__file", "C:/Users/bzm15/Desktop/ix/mini_web-develop/pages/community/index.vue"]]);
wx.createPage(MiniProgramPage);
