<template>
  <modal id="app-sms-template-modal"
         v-model="showModal"
         :title="generateModalTitle('sms_template')"
         @submit="submitData" :loading="loading"
         :preloader="preloader">
    <form
        ref="form"
        :data-url='selectedUrl ? selectedUrl : SMS_TEMPLATE'
        @submit.prevent="submitData">

      <app-form-group
          type="text"
          :label="$t('subject')"
          :placeholder="$placeholder('subject')"
          v-model="formData.subject"
          :required="true"
          :error-message="$errorMessage(errors, 'subject')">
      </app-form-group>

      <app-form-group
          type="textarea"
          :label="$t('content')"
          :placeholder="$placeholder('content')"
          v-model="formData.content"
          :required="true"
          :footer-content="footer_content"
          :error-message="$errorMessage(errors, 'content')">
      </app-form-group>

<!--      <div class="col-6 d-flex align-items-center justify-content-between">-->
<!--        <label> {{ $t('is_default') }}: </label>-->
<!--        <span :key="formData.is_default == true ? 'check-square' : 'square'" class="btn py-2 px-2 padding-x-10"-->
<!--              @click="handleCheckBoxClick">-->
<!--                    <app-icon-->
<!--                        class="size-19 primary-text-color"-->
<!--                        :name="formData.is_default == true ? 'check-square' : 'square'"-->
<!--                    />-->
<!--                </span>-->
<!--      </div>-->

    </form>
  </modal>
</template>

<script>
import FormHelperMixins from "../../../../../common/Mixin/Global/FormHelperMixins";
import ModalMixin from "../../../../../common/Mixin/Global/ModalMixin";
import {SMS_TEMPLATE} from "../../../../Config/ApiUrl-CPB";

export default {
  name: "SmsTemplateAddEditModal",
  mixins: [FormHelperMixins, ModalMixin],
  data() {
    return {
      formData: {
        is_default: false
      },
      SMS_TEMPLATE,
      footer_content: "{company_name}, {first_name}, {last_name}, {invoice_id}, {total}"
    }
  },
  methods: {
    handleCheckBoxClick() {
      this.formData.is_default = this.formData.is_default == true ? false : true;
    },
    afterSuccess({data}) {
      this.formData = {};
      $('#app-sms-template-modal').modal('hide');
      this.$emit('input', false);
      this.toastAndReload(data.message, 'sms-template-table');
    },
    afterSuccessFromGetEditData(response) {
      this.preloader = false;
      this.formData = response.data;
    },
  },
}
</script>