<template>
  <div class="position-relative">
    <form>
      <div class="form-row">
        <label for="">عنوان </label>
        <span>{{ data.entity.title }}</span>
      </div>

      <div class="form-row">
        <input
          class="form-control col"
          placeholder="عنوان را وارد کنید"
          type="text"
          id="title"
          name="title"
          v-model.trim="value.title"
        />
      </div>
      <div class="form-row">
        <textarea
          v-model="value.text"
          name="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>
        <button
          class="btn delete-btn btn-outline-danger button_delete_Simple"
          @click.prevent="deleteProperty()"
        >
          حذف
        </button>
      </div>
    </form>
  </div>
</template>

<script>
import { propertyMixin } from "~/chat/mixins/propertyMixin";
import repoApi from "~/apis/repoApi";
export default {
  mixins: [propertyMixin],

  props: {
    data: { type: Object, default: () => ({}) },
  },
  mounted() {
    // this.value = ('description' in this.data.entity ) ?  this.data.entity['description'] : '';
    this.value = this.getPropertyValue(
      this.data.entity,
      this.data.keyName,
      this.data.index
    );
  },
  data() {
    return {
      value: {},
    };
  },
  

  methods: {
    deleteSimple(value = "") {
      mySwalConfirm({
        title: "هشدار!!!",
        html: `از حذف این مورد اطمینان دارید؟ `,
        icon: "warning",
      }).then((result) => {
        //  let word =this.data.keyName
        //  word=undefined
        let url =
          repoApi.entity.edit + this.data.entity.id + `/${this.data.keyName}`;
        const formData = {
          [this.data.keyName]: value,
        };
        // let url=`edit/${this.data.entity.id}/${this.data.keyName}`;
        ApiService.postRequest(url, formData)
          .then((res) => {
            this.closeModal();

            mySwalToast({
              html: res.data.message,
              icon: "success",
            });
          })
          .catch((err) => {
            mySwalToast({
              title: "خطا!!!",
              html: err.message,
              icon: "error",
            });
          });
      });
    },
  },
};
</script>
<style scoped>
/* .button_delete_Simple {
  position: absolute;
  bottom: 16px;
  right: 5px;
} */
</style>
