<template>
  <div class="position-relative">
    <form>
      <div class="form-row text__14">
        <label for="">مساله </label>
        <span>{{ data.entity.title }}</span>
      </div>
      <div class="form-row">
        <label for="">چکیده </label>
        <textarea
          name=""
          id=""
          v-model="propertyObj.value_json.text"
          cols="30"
          rows="30"
          placeholder="چکیده ای از پاسخ را گویا بیان فرمایید"
        ></textarea>
      </div>

      <div class="popUp-tab__buttons">
        <button
          title="لغو"
          @click.prevent="$emit('close-modal')"
          class="popUp-tab__clear btn"
          type="button"
        >
          لغو
        </button>
        <button
          type="button"
          class="popUp-tab__submit btn"
          @click.prevent="saveProperty()"
        >
          ثبت
        </button>
      </div>
      <!-- <div class="popUp-tab__buttons"> -->
      <!-- <a href="javascript:void(0)" class="popUp-tab__clear" @click="closeModal()">لغو</a> -->
      <!-- <a href="javascript:void(0)" class="popUp-tab__clear" data-dismiss="modal" ref="closeSummeryModal" >لغو</a> -->
      <!-- <a href="javascript:void(0)" class="popUp-tab__submit" @click="saveProperty()">ثبت</a> -->
      <!-- </div> -->
    </form>
  </div>
</template>
<script>
import { mapActions } from "pinia";
export default {
  props: {
    data: { type: Object, default: () => ({}) },
  },
  data() {
    return {
      property: {
        value_json: {
          text: "",
        },
      },
    };
  },

  computed: {
    propertyObj() {
      if (this.data.property) {
        return this.data.property;
      } else {
        return this.property;
      }
    },
  },

  methods: {
    ...mapActions("jahat", ["SAVE_SUMMARY"]),

    saveProperty() {
      let self = this;
      let property = this.propertyObj;
      let index = 0;

      this.SAVE_SUMMARY({ property, vm: this }).then((response) => {
        self.$emit("change", {
          item: response.data,
          type: "summeries",
          index: index,
        });
        self.closeModal();
      });
    },

    closeModal() {
      this.propertyObj.value_json = { text: "" };
      this.$refs.closeSummeryModal.click();
    },
  },
};
</script>
