<template>
  <div class="full-security" v-if="data && !isFull">
    <div class="btns">
      <span v-for="v in views" @click="active = v" class="fun-ctrl">
        {{ v.name }}
      </span>
    </div>

    <div class="view" v-if="active">
      <ui-icon type="close" ctrl class="close" @click="active = void 0" />
      <h2>{{ active.name }}</h2>
      <!-- <component :is="active.view" v-if="mdata" /> -->

      <template v-if="mdata">
        <div class="item" v-for="item in mdata.items">
          <h3 class="title">{{ item.title }}</h3>
          <div class="content">
            <p v-for="c in item.content" :class="{ link: c.link, zk: kzs.includes(c) }">
              {{ kzs.includes(c) ? c.zk : c.title }}
              <Link :name="c.link" v-if="c.link" :fly-link="flyLink" :type="c.type" />
              <span
                class="mspan fun-ctrl"
                v-else-if="c.zk"
                @click="
                  kzs.includes(c) ? (kzs = kzs.filter((i) => i !== c)) : kzs.push(c)
                "
              >
                {{ kzs.includes(c) ? "收起" : "更多" }}
              </span>
            </p>
          </div>
        </div>
      </template>
    </div>
  </div>

  <Mode />
</template>

<script setup lang="ts">
import { computed, reactive, ref } from "vue";
import { data, flyLink as flyLinkRaw } from "./store";
import Link from "./link.vue";
import Mode from "./mode.vue";

const isFull = ref(false);
const flyLink = async (name: string, type?: string) => {
  isFull.value = true;
  await flyLinkRaw(name, type);
  isFull.value = false;
};

const kzs = ref<any[]>([]);
const views = reactive([
  { name: "职责要求", view: "0" },
  { name: "场所情况", view: "1" },
  { name: "勤务要求", view: "2" },
]);
const active = ref<typeof views[0]>();
const mdata = computed(() => {
  return active.value && data[Number(active.value?.view)];
});
</script>

<style lang="scss" scoped>
.full-security {
  position: absolute;
  z-index: 9;
  inset: 0;
  pointer-events: none;

  > * {
    pointer-events: all;
  }
}

.btns {
  position: absolute;
  bottom: 40px;
  left: 50%;
  display: flex;
  transform: translate(-50%, 0);

  span {
    cursor: pointer;
    margin: 0 35px;
    background: rgba(0, 0, 0, 0.9);
    width: 110px;
    height: 85px;
    text-align: center;
    line-height: 85px;
    color: #fff;
    font-size: 14px;
    border-radius: 6px;
  }
}

.view {
  position: absolute;
  right: 24px;
  top: 24px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.9);
  bottom: 24px;
  width: 536px;
  overflow-y: auto;
  padding: 30px;

  .close {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 20px;
  }

  > h2 {
    font-size: 18px;
    font-weight: bold;
  }
}

.c-item {
  margin-top: 10px;

  p {
    display: flex;
    align-items: center;
    justify-content: space-between;

    img {
      height: 15px;
      cursor: pointer;
    }
  }
}

.item:not(:last-child) .content {
  margin-bottom: 20px;
  border-bottom: 1px solid #000;
  padding-bottom: 20px;
}

.jb {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.item {
  margin-top: 20px;

  h3 {
    font-size: 15px;
    margin-bottom: 10px;
  }

  p {
    font-size: 14px;
    line-height: 1.89em;
    color: #9e9e9e;

    &.link {
      color: #fff;
      margin: 6px 0;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    span {
      float: right;
      cursor: pointer;
    }

    &.zk {
      white-space: pre-line;
      span {
        float: none;
        display: block;
        text-align: center;
      }
    }
  }
}
</style>
