<template>
  <div class="sign-up__form">
    <div class="sign-up__form-inputs">
      <div class="sign-up__form-row sign-up__simple-input">
        <div class="form-group position-relative">
          <label for="">عنوان:</label>
          <input
            class="form-control elem__placeholder-gray"
            v-model.trim="value.title"
            type="text"
            placeholder="عنوان"
            autocomplete="on"
          />
        </div>
      </div>

      <div class="sign-up__form-row sign-up__simple-input">
        <div class="form-group position-relative">
          <label for="">سازمان:</label>
          <input
            class="form-control elem__placeholder-gray"
            v-model.trim="value.organ"
            type="text"
            placeholder="سازمان"
            autocomplete="on"
          />
        </div>
        <div class="d-flex justify-content-end">
          <div class="sign-up__btn-container ml-3">
            <a @click="closeForm()" class="btn">انصراف</a>
          </div>

          <button class="btn btn-primary" @click="submit()">
            <the-button-loading v-if="loading"></the-button-loading>
            <div v-if="value.id">
              {{ $t("Update") }}
            </div>
            <div v-else>
              {{ $t("Save") }}
            </div>
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import taskApi from "~/apis/taskApi";


export default {
  beforeMount() {
    this.httpService = new HttpService(
      import.meta.env.VITE_BASE_URL + taskUrl()
    );
  },
  props: {
    parentLoading: false,
    teamData: {
      default() {
        return {
          id: undefined,
          organ: null,
          title: null,
        };
      },
    },
  },
  watch: {
    teamData(newValu) {
      this.value = newValu;
    },
    parentLoading(newVal) {
      this.loading = newVal;
    },
  },
  mounted() {
    this.value = this.teamData;
  },
  data() {
    return {
      // organ: "",
      // title: "",
      loading: this.parentLoading,
      value: {
        id: undefined,
        organ: null,
        title: null,
      },
    };
  },
  computed: {
    taskUrl() {
      return import.meta.env.VITE_TASK;
    },
  },
  methods: {
    submit() {
      this.loading = true;
      this.$emit("on-pass-by-emit", this.value);
    },
    // addTeams() {
    //   this.$emit("add-teams");
    // },
    closeForm() {
      this.$emit("close-form");
    },
    // getGroups() {
    //   this.$emit("get-groups");
    // },
    // addTeams() {
    //   let url = taskApi.taskTeams.add;
    //   let payload = {
    //     title: this.value.title,
    //     organ: this.value.organ,
    //   };
    //   this.httpService
    //     .postRequest(url, payload)
    //     .then((res) => {
    //       this.mySwalToast({
    //         html: res.message,
    //       });
    //     })
    //     .finally(() => {
    //       this.getGroups();
    //     });
    // },
  },
};
</script>
<style scoped lang="scss">
// input::placeholder {
//   color: #d7d7d7;
// }
</style>
