<template>
  <div class="organization_list" ref="container">
    <organization-card
      v-for="(item, index) in data"
      :key="'organization_card_' + index"
      :data="item"
      @delete-action="deleteAction"
      :details-url="detailsUrl"
      :style="{ width: 'calc(100% / ' + rowNum + ' - 36px)' }"
    ></organization-card>
  </div>
</template>

<script>
import organizationCard from "./organization-card";

export default {
  components: {
    organizationCard,
  },
  props: {
    data: {
      type: Array,
      default: [],
    },
    detailsUrl: {
      type: String,
      default: 0,
    },
  },
  data: () => ({
    rowNum: 5,
  }),
  methods: {
    deleteAction(item) {
      this.$emit("delete-action", item);
    },
    pageResize() {
      let listWidth = this.$refs.container.clientWidth;
      this.rowNum = Math.floor(listWidth / 310);
    },
  },
  mounted() {
    this.pageResize();
    window.onresize = () => {
      this.pageResize();
    };
  },
};
</script>

<style scoped>
.organization_list {
  margin: 20px -20px 0;
  padding: 30px 0 0;
  border-top: 1px solid #e3e5ef;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: flex-start;
}
</style>
