<template>
  <v-layout class="mb-2" column>
    <v-dialog v-model="dialogconfirmationdelete" persistent max-width="290">
      <v-card>
        <v-card-title dark class="headline error pt-2 pb-2" primary-title style="color: white">
          <h4 dark>Konfirmasi</h4>
        </v-card-title>
        <v-card-text>
          {{ msgconfirmationdelete }}
        </v-card-text>
        <v-card-actions>
          <v-spacer></v-spacer>
          <v-btn small color="error darken-1 text-sm-left" flat @click="doDeleteData()">Hapus</v-btn>
          <v-btn small color="primary darken-1 text-sm-right" flat
            @click="dialogconfirmationdelete = false">Batal</v-btn>
        </v-card-actions>
      </v-card>
    </v-dialog>

    <!-- alert dialog error start -->
    <v-dialog v-model="dialogerror" persistent max-width="290">
      <v-card>
        <v-card-title color="error" class="headline">Error !</v-card-title>
        <v-card-text>
          {{ msgerror }}
        </v-card-text>
        <v-card-actions>
          <v-spacer></v-spacer>
          <v-btn color="green darken-1" flat @click="closeDialogError">OK</v-btn>
        </v-card-actions>
      </v-card>
    </v-dialog>
    <!-- alert dialog error end -->

    <!-- dialog detail paket -->
    <v-dialog v-model="dialogconfirmationdetailpaket" persistent max-width="900">
      <v-card>
        <v-card-title dark class="headline primary pt-2 pb-2" primary-title
          style="color: white; display: flex; justify-content: space-between">
          <h4 dark>
            Detail Paket [&nbsp;{{
              this.selected_detail_paketx.T_PacketSasCode
            }}
            - {{ this.selected_detail_paketx.T_PacketName }}&nbsp;]
          </h4>
          <v-btn icon @click="dialogconfirmationdetailpaket = false" class="pt-2 pb-2" style="color: white">
            <v-icon>close</v-icon>
          </v-btn>
        </v-card-title>
        <!-- <v-card-text> -->
        <!-- <table>
                        <tr>
                            <td>Pemeriksaan</td>
                            <td>Harga</td>
                        </tr>
                        <tr v-for="item in xdetailpackets" :key="item.T_PacketDetailID">
                            <td>{{ item.T_TestName }}</td>
                            <td>{{ item.T_PacketDetailPrice }}</td>
                        </tr>
                    </table> -->
        <v-layout row pa-2 align-center wrap>
          <table style="
              font-family: arial, sans-serif;
              border-collapse: collapse;
              width: 100%;
              background: white;
              border: 0px;
            ">
            <tr>
              <th class="text-md-left pt-2 pb-2" style="
                  border: 1px solid black;
                  border-collapse: collapse;
                  padding-top: 2px;
                  padding-bottom: 2px;
                  padding-left: 20px;
                ">
                PEMERIKSAAN
              </th>
              <th class="text-md-right pt-2 pb-2" style="
                  border: 1px solid black;
                  border-collapse: collapse;
                  padding-top: 2px;
                  padding-bottom: 2px;
                  padding-right: 20px;
                ">
                HARGA
              </th>
            </tr>
            <tr class="mini-input" v-if="xdetailpackets.length > 0" v-for="(note, index) in xdetailpackets">
              <td width="80%" class="text-md-left pl-3 pr-3" style="
                  border: 1px solid black;
                  border-collapse: collapse;
                  padding-top: 2px;
                  padding-bottom: 2px;
                ">
                {{ note.T_TestName }}
              </td>
              <td width="20%" class="text-md-right pl-3 pr-3" style="
                  border: 1px solid black;
                  border-collapse: collapse;
                  padding-top: 2px;
                  padding-bottom: 2px;
                ">
                {{ convertMoney(note.T_PacketDetailPrice) }}
              </td>
            </tr>
            <tr class="mini-input" v-if="xdetailpackets.length === 0">
              <td colspan="5" class="text-md-center pr-2" style="
                  border: 1px solid black;
                  border-collapse: collapse;
                  padding-top: 2px;
                  padding-bottom: 2px;
                ">
                Tidak ada data
              </td>
            </tr>
          </table>
        </v-layout>

        <!-- </v-card-text> -->
        <v-card-actions>
          <v-spacer></v-spacer>
          <v-btn small color="primary darken-1 text-sm-right" flat
            @click="dialogconfirmationdetailpaket = false">Close</v-btn>
        </v-card-actions>
      </v-card>
    </v-dialog>
    <!-- dialog detail paket -->

    <v-card>
      <v-layout row>
        <v-flex xs12>
          <v-subheader red--text text--lighten-1>
            SETUP FORM
            <!-- <v-flex text-md-right> -->
            <!-- <v-btn v-if="status.id === 'N'" @click="downloadxapp()" small color="info">download</v-btn> -->
            <!-- <v-btn v-if="xact === 'edit'" @click="validasiCreateSSMou()" small color="info">Validasi</v-btn> -->
            <!-- </v-flex> -->
          </v-subheader>
          <v-divider></v-divider>
          <v-layout row wrap>
            <v-flex xs12 pa-2>
              <v-layout row>
                <!-- label -->
                <v-flex xs6 pa-1>
                  <v-text-field color="black" label="Label Setup MCU" v-model="inp_Mgm_McuLabel" outline
                    hide-details></v-text-field>
                  <p v-if="_.isEmpty(inp_Mgm_McuLabel)" class="error caption mt-1 mb-0 pl-2 pr-2" style="color: #fff">
                    Belum isi label
                  </p>
                </v-flex>
                <!-- label -->
                <!-- autocomplete Corporate -->
                <v-flex xs6 pa-1>
                  <v-autocomplete style="font-size: 12px" label="Cari Corporate ..." v-model="xcorporate"
                    :items="xcorporates" :search-input.sync="search_corporate" auto-select-first outline no-filter
                    item-text="name" return-object :loading="is_loading" hide-details no-data-text="Pilih Corporate">
                    <template slot="item" slot-scope="{ item }">
                      <v-list-tile-content>
                        <v-list-tile-title v-text="item.name"></v-list-tile-title>
                      </v-list-tile-content>
                    </template>
                  </v-autocomplete>
                  <p v-if="_.isEmpty(xcorporate)" class="error caption mt-1 mb-0 pl-2 pr-2" style="color: #fff">
                    Belum milih Corporate
                  </p>
                </v-flex>
                <!-- autocomplete Corporate -->
              </v-layout>
            </v-flex>
            <v-flex x12 pa-2>
              <v-layout row>
                <v-flex xs12 pa-1>
                  <p class="subheader">Email Result</p>
                  <v-radio-group v-model="mgm_mcuemailresult.Mgm_McuEmailResultIsPatientEmail"
                    @change="changeEmailResult(mgm_mcuemailresult.Mgm_McuEmailResultIsPatientEmail)">
                    <v-radio label="Patient Email" value="P"></v-radio>
                    <v-radio label="Corporate Email" value="C"></v-radio>
                    <v-radio label="Patient & Corporate Email" value="X"></v-radio>
                  </v-radio-group>
                </v-flex>
                <v-flex xs12 pa-1>
                  <v-text-field v-model="mgm_mcuemailresult.CorporateEmail" label="Corporate Email" disabled
                    placeholder="Corporate Email" outline hide-details></v-text-field>
                </v-flex>
              </v-layout>
            </v-flex>
            <v-flex xs12 pa-2>
              <v-layout row>
                <!-- tanggal start date -->
                <v-flex xs3 pa-1>
                  <v-menu v-model="menufilterdatestart" :close-on-content-click="false" :nudge-right="40" lazy
                    transition="scale-transition" offset-y hide-details full-width max-width="290px" min-width="290px">
                    <template v-slot:activator="{ on }">
                      <v-text-field v-model="filterComputedDateFormattedStart" label="Tanggal Pelaksanaan Awal"
                        style="font-size: 12px" outline hide-details readonly v-on="on" @blur="
                          date = deFormatedDate(
                            filterComputedDateFormattedStart
                          )
                          "></v-text-field>
                    </template>
                    <v-date-picker v-model="xdatestart" no-title @input="menufilterdatestart = false"></v-date-picker>
                  </v-menu>
                </v-flex>
                <!-- tanggal start date -->

                <!-- tanggal end date -->
                <v-flex xs3 pa-1>
                  <v-menu v-model="menufilterdateend" :close-on-content-click="false" :nudge-right="40" lazy
                    transition="scale-transition" offset-y full-width hide-details max-width="290px" min-width="290px">
                    <template v-slot:activator="{ on }">
                      <v-text-field v-model="filterComputedDateFormattedEnd" label="Tanggal Pelaksanaan Akhir" outline
                        style="font-size: 12px" readonly hide-details v-on="on" @blur="
                          date = deFormatedDate(filterComputedDateFormattedEnd)
                          "></v-text-field>
                    </template>
                    <v-date-picker :min="xdatestart" v-model="xdateend" no-title
                      @input="menufilterdateend = false"></v-date-picker>
                  </v-menu>
                </v-flex>
                <!-- tanggal end date -->
                <!-- relasi bayar sendiri -->
                <v-flex xs3 pa-1>
                  <v-checkbox v-model="inp_Mgm_McuFlagRelasiBayarSendiri"
                    label="Relasi bayar sendiri (outsource)"></v-checkbox>
                </v-flex>
                <!-- relasi bayar sendiri end -->
                <!-- relasi bayar sendiri -->
                <v-flex xs3 pa-1 class="text-sm-right">
                  <v-checkbox v-model="inp_Mgm_McuBisaTambahPemeriksaan" label="Bisa tambah Pemeriksaan"></v-checkbox>
                </v-flex>
              </v-layout>
            </v-flex>

            <v-flex xs12 pa-2>
              <v-layout row>
                <!-- pic name -->
                <v-flex xs4 pa-1>
                  <v-text-field color="black" label="PIC Name" placeholder="PIC Name" v-model="inp_Mgm_McuPicName"
                    outline hide-details></v-text-field>
                  <p v-if="_.isEmpty(inp_Mgm_McuPicName)" class="error caption mt-1 mb-0 pl-2 pr-2" style="color: #fff">
                    Belum isi PIC Name
                  </p>
                </v-flex>
                <!-- pic name -->
                <!-- email -->
                <v-flex xs4 pa-1>
                  <v-text-field color="black" label="PIC Email" placeholder="PIC Email" v-model="inp_Mgm_McuPicEmail"
                    outline hide-details type="email" @keyup="validateEmail()"></v-text-field>
                  <p v-if="_.isEmpty(inp_Mgm_McuPicEmail)" class="error caption mt-1 mb-0 pl-2 pr-2"
                    style="color: #fff">
                    Belum isi PIC email
                  </p>
                  <p v-if="
                    !_.isEmpty(inp_Mgm_McuPicEmailValidate) &&
                    !_.isEmpty(inp_Mgm_McuPicEmail)
                  " class="error caption mt-1 mb-0 pl-2 pr-2" style="color: #fff">
                    {{ inp_Mgm_McuPicEmailValidate }}
                  </p>
                </v-flex>
                <!-- email -->
                <!-- password -->
                <v-flex xs4 pa-1>
                  <v-text-field color="black" label="PIC Password" placeholder="PIC Password"
                    v-model="inp_Mgm_McuPicPassword" outline hide-details type="password"
                    :append-icon="xshow1 ? 'visibility' : 'visibility_off'" :type="xshow1 ? 'text' : 'password'"
                    @click:append="xshow1 = !xshow1"></v-text-field>
                  <p v-if="_.isEmpty(inp_Mgm_McuPicPassword)" class="error caption mt-1 mb-0 pl-2 pr-2"
                    style="color: #fff">
                    Belum isi PIC password
                  </p>
                </v-flex>
                <!-- password -->
              </v-layout>
            </v-flex>
            <v-flex xs12 pa-2>
              <v-layout row>
                <!-- branch -->
                <v-flex xs6 pa-1>
                  <v-autocomplete :items="xbranchCb" v-model="selected_branchCb" item-text="M_BranchName" hide-details
                    outline item-value="M_BranchID" return-object label="Cabang">
                  </v-autocomplete>
                  <p v-if="_.isEmpty(selected_branchCb)" class="error caption mt-1 mb-0 pl-2 pr-2" style="color: #fff">
                    Belum pilih cabang
                  </p>
                </v-flex>
                <!-- branch -->
                <!-- dropdown tprice header -->
                <v-flex xs6 pa-1>
                  <v-autocomplete :items="xtpriceheaderformCb" v-model="selected_tpriceheaderformCb"
                    item-text="T_PriceHeaderName" hide-details item-value="T_PriceHeaderID" return-object
                    label="Price Header" outline @change="changePriceHeaderForm">
                  </v-autocomplete>
                  <p v-if="_.isEmpty(selected_tpriceheaderformCb)" class="error caption mt-1 mb-0 pl-2 pr-2 pb-2"
                    style="color: #fff">
                    Belum pilih price header
                  </p>
                </v-flex>
                <!-- dropdown tprice header -->
              </v-layout>
            </v-flex>
            <v-flex xs12 pa-2>
              <!-- catatan -->
              <v-textarea label="Catatan" v-model="inp_Mgm_McuNote"></v-textarea>
              <!-- catatan -->
            </v-flex>
            <!-- paket -->
            <v-flex xs12 pa-2>
              <v-card class="mb-2" color="cyan">
                <v-layout row>
                  <v-flex xs12 pt-2 pb-1 pl-2 pr-2>
                    <v-card>
                      <v-layout align-center row>
                        <h4 class="subheader pl-3 pt-2 pb-2">DAFTAR PAKET</h4>
                      </v-layout>
                      <v-divider></v-divider>
                      <v-layout align-center row>
                        <v-flex pt-1 pl-2 pr-2 pb-1 xs12>
                          <v-text-field color="cyan" label="Cari" placeholder="Cari paket" v-model="search_packet"
                            @keyup.enter="searchPacket()" outline single-line hide-details></v-text-field>
                        </v-flex>
                      </v-layout>
                    </v-card>
                  </v-flex>
                </v-layout>
                <v-layout row>
                  <v-flex xs12 pt-1 pb-1 pl-2 pr-2>
                    <v-data-table :items="packets" class="v-table elevation-1" hide-actions hide-headers>
                      <template v-slot:items="props">
                        <!-- <td style="height:42px" @click="getDetailPacket(props.item)">{{ props.item.code }}</td> -->
                        <td style="height: 42px" v-on:dblclick="getDetailPacket(props.item)">
                          {{ props.item.code }}
                        </td>
                        <td style="height: 42px" v-on:dblclick="getDetailPacket(props.item)">
                          {{ props.item.name }}
                        </td>
                        <td class="text-xs-right" style="height: 42px">
                          <v-btn dark v-if="packetExist(props.item)" @click="addToPackets(props.item)"
                            style="min-width: 25px; height: 30px" small color="cyan">
                            <v-icon style="cursor: pointer; font-size: 18px">
                              add_box
                            </v-icon>
                          </v-btn>
                          <v-btn dark v-if="!packetExist(props.item)" @click="removeFromPackets(props.item)"
                            style="min-width: 25px; height: 30px" small color="red">
                            <v-icon style="cursor: pointer; font-size: 18px">
                              delete
                            </v-icon>
                          </v-btn>
                        </td>
                      </template>
                    </v-data-table>
                  </v-flex>
                </v-layout>
                <v-layout row>
                  <v-flex xs12 pt-1 pb-1 pl-2 pr-2>
                    <v-card>
                      <v-layout row>
                        <v-pagination color="cyan" style="margin-top: 10px; margin-bottom: 10px"
                          v-model="current_page_packet" :length="total_patient_packet"></v-pagination>
                      </v-layout>
                    </v-card>
                  </v-flex>
                </v-layout>
                <v-layout row>
                  <v-flex xs12 pt-2>
                    <p v-if="_.isEmpty(selected_packets)" class="error caption mt-1 mb-0 pl-2 pr-2" style="color: #fff">
                      Belum milih paket
                    </p>
                  </v-flex>
                </v-layout>
              </v-card>
            </v-flex>
            <!-- paket -->

            <!-- template fisik -->
            <v-flex xs12 pa-2>
              <v-autocomplete :items="xtemplatefisikCb" v-model="selected_templateFisikCb"
                item-text="FisikTemplateMappingName" hide-details outline item-value="FisikTemplateMappingID"
                return-object label="Template Fisik">
              </v-autocomplete>
              <p v-if="_.isEmpty(selected_templateFisikCb)" class="error caption mt-1 mb-0 pl-2 pr-2"
                style="color: #fff">
                Belum milih Template Fisik
              </p>
            </v-flex>
            <!-- template fisik -->

            <!-- Report hasil -->
            <v-flex xs12 pa-2>
              <v-radio-group hide-details v-model="reportresult">
                <template v-slot:label>
                  <h4 class="subheader pl-2 pt-2 pb-2">REPORT HASIL</h4>
                </template>
                <v-layout pt-2 row>
                  <v-flex xs12 pa-1>
                    <v-radio value="1">
                      <template v-slot:label>
                        <div>1 Tahunan</div>
                      </template>
                    </v-radio>
                  </v-flex>
                  <v-flex xs12 pa-1>
                    <v-radio value="2">
                      <template v-slot:label>
                        <div>2 Tahunan</div>
                      </template>
                    </v-radio>
                  </v-flex>
                  <v-flex xs12 pa-1>
                    <v-radio value="H">
                      <template v-slot:label>
                        <div class="text-no-wrap">Report Haji</div>
                      </template>
                    </v-radio>
                  </v-flex>
                </v-layout>
              </v-radio-group>
            </v-flex>
            <!-- Report hasil -->

            <!--LBP-->
            <v-flex xs12 pa-1 pl-3>
              <v-checkbox v-model="inp_Mgm_McuLowBackPainTampilSemua"
                label="LBP tampil semua (meski negatif)"></v-checkbox>
            </v-flex>
            <!--LBP-->

            <!-- generate password by -->
            <v-flex xs12 pa-2>
              <v-autocomplete :items="xgeneratepasswordby" v-model="selected_generatepasswordby"
                item-text="generatepasswordbyname" hide-details outline item-value="generatepasswordbycode"
                return-object label="Generate Password By">
              </v-autocomplete>
              <p v-if="_.isEmpty(selected_generatepasswordby)" class="error caption mt-1 mb-0 pl-2 pr-2"
                style="color: #fff">
                Belum milih generate password by
              </p>
            </v-flex>
            <!-- generate password by -->

            <!-- mcu user -->
            <v-flex xs12 pa-2>
              <v-layout row>
                <!-- email -->
                <v-flex xs4 pa-1>
                  <v-text-field color="black" label="Email User MCU" placeholder="Email User MCU"
                    v-model="inp_Mgm_McuUserEmail" outline hide-details type="email"
                    @keyup="validateUserEmail()"></v-text-field>
                  <p v-if="checkError('requireusermcuemail')" class="error pl-2 pr-2" style="color:#fff">Belum isi email
                    user</p>
                  <!-- <p
                    v-if="_.isEmpty(inp_Mgm_McuUserEmail)"
                    class="error caption mt-1 mb-0 pl-2 pr-2"
                    style="color: #fff"
                  >
                    Belum isi email user
                  </p> -->
                  <p v-if="
                    !_.isEmpty(inp_Mgm_McuUserEmailValidate) &&
                    !_.isEmpty(inp_Mgm_McuUserEmail)
                  " class="error caption mt-1 mb-0 pl-2 pr-2" style="color: #fff">
                    {{ inp_Mgm_McuUserEmailValidate }}
                  </p>
                </v-flex>
                <!-- email -->
                <!-- password -->
                <v-flex xs4 pa-1>
                  <v-text-field color="black" label="User Password" placeholder="User Password"
                    v-model="inp_Mgm_McuUserPassword" outline hide-details type="password"
                    :append-icon="xshow1 ? 'visibility' : 'visibility_off'" :type="xshow1 ? 'text' : 'password'"
                    @click:append="xshow1 = !xshow1"></v-text-field>
                  <p v-if="checkError('requireusermcupassword')" class="error pl-2 pr-2" style="color:#fff">Belum isi
                    password user
                  </p>
                  <!-- <p
                    v-if="_.isEmpty(inp_Mgm_McuUserPassword)"
                    class="error caption mt-1 mb-0 pl-2 pr-2"
                    style="color: #fff"
                  >
                    Belum isi password user
                  </p> -->
                </v-flex>
                <!-- password -->

                <v-flex pa-1 v-if="!_.isEmpty(inp_Mgm_McuUserEmail) && !_.isEmpty(inp_Mgm_McuUserPassword)">
                  <v-btn @click="saveUserMcu" color="warning">Tambahkan</v-btn>
                </v-flex>
                <v-flex pa-1>
                  <v-btn v-if="show_delete" @click="deleteUserMcu()" small color="error">Hapus</v-btn>
                </v-flex>
              </v-layout>
            </v-flex>
            <!-- end mcu user -->

            <!-- data tabel mcu user -->
            <v-flex xs12 pa-2>
              <v-layout row>
                <v-flex xs12>
                  <v-data-table :headers="headers" :items="xUserMculists" hide-actions class="elevation-1">
                    <template v-slot:headers="props">
                      <tr>
                        <th style="width:20px" class="blue-grey white--text">
                          <v-checkbox style="padding-top:0;margin-top:0" hide-details color="white"
                            :indeterminate="indeterminatex" @change="changeCbxAllX(bar_chx_allx)"
                            v-model="bar_chx_allx"></v-checkbox>
                        </th>
                        <th v-for="header in props.headers" :key="header.text" :class="header.class"
                          :width="header.width">
                          {{ header.text }}
                        </th>
                      </tr>
                    </template>

                    <template v-slot:items="props">
                      <tr :key="props.index">
                        <td style="width:20px" class="text-xs-left">
                          <v-checkbox style="padding-top:0;margin-top:0" color="blue-grey" hide-details
                            v-model="props.item.chex" @change="checkTopX()"></v-checkbox>
                        </td>
                        <td class="text-xs-left pa-2">
                          {{ props.item.Mgm_McuUserEmail }}
                        </td>
                        <td class="text-xs-center pa-2">
                          <v-btn title="hapus data temporary" style="min-width:20px"
                            @click="deleteTempUserMcuRow(props.index)" small color="error"><v-icon
                              small>delete</v-icon></v-btn>
                        </td>
                      </tr>
                    </template>
                  </v-data-table>
                </v-flex>
              </v-layout>
            </v-flex>
            <!-- end data tabel mcu user -->

          </v-layout>
        </v-flex>
      </v-layout>

      <!-- tombol save -->
      <!-- <v-layout v-if="!_.isEmpty(xordercompany) && xseldoctors.length > 0 && xselmous.length > 0 && !_.isEmpty(default_mou) && !_.isEmpty(default_doctor) && !_.isEmpty(default_doctor_address)" pa-2 row>
                <v-flex xs12><v-btn @click="savesetup" class="deep-orange accent-1 white--text" block>SIMPAN</v-btn></v-flex>
            </v-layout> -->

      <v-layout pa-2 row v-if="
        !_.isEmpty(inp_Mgm_McuLabel) &&
        !_.isEmpty(xcorporate) &&
        !_.isEmpty(inp_Mgm_McuPicName) &&
        !_.isEmpty(inp_Mgm_McuPicPassword) &&
        !_.isEmpty(inp_Mgm_McuPicEmail) &&
        !_.isEmpty(selected_templateFisikCb) &&
        !_.isEmpty(selected_branchCb) &&
        !_.isEmpty(selected_tpriceheaderformCb) &&
        !_.isEmpty(mgm_mcuemailresult.Mgm_McuEmailResultIsPatientEmail) &&
        mgm_mcuemailresult.Mgm_McuEmailResultIsPatientEmail !== 'N' &&
        !_.isEmpty(selected_generatepasswordby)
      ">
        <v-flex xs12><v-btn @click="savesetupX" class="deep-orange accent-1 white--text" block>SIMPAN</v-btn></v-flex>
      </v-layout>
      <!-- tombol save -->
    </v-card>

    <one-dialog-print title="" width="850" height="650" :status="openprint" :urlprint="urlprint"
      @close-dialog-print="openprint = false"></one-dialog-print>
  </v-layout>
</template>

<style scoped>
table,
td,
th {
  border: 1px solid #ddd;
  text-align: left;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  padding-top: 5px;
  padding-bottom: 5px;
  padding-left: 8px;
  padding-right: 5px;
}

.mini-input .v-input {
  margin-top: 0px;
}

.mini-input .v-input,
.mini-input .v-input--selection-controls,
.mini-input .v-input__slot {
  margin-top: 0px;
  margin-bottom: 0px;
  margin-left: 3px;
}

.mini-input .v-messages {
  min-height: 0px;
}

input.fhm-input {
  border: 1px solid black;
  border-radius: 2px;
  -webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.1),
    0 0 4px rgba(0, 0, 0, 0.1);
  -moz-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.1), 0 0 4px rgba(0, 0, 0, 0.1);
  box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.1), 0 0 4px rgba(0, 0, 0, 0.1);
  padding: 2px 4px;
  background: rgba(255, 255, 255, 0.5);
  margin: 0 0 1px 0;
  width: 30px;
  text-align: center;
}

.v-date-picker-table {
  height: auto !important;
}
</style>

<script>
module.exports = {
  components: {
    "one-dialog-print": httpVueLoader("../../common/oneDialogPrintX.vue"),
  },
  mounted() {
    this.$store.dispatch("patient/getTemplateFisikMapping");
    this.$store.dispatch("patient/getBranch");
    this.$store.dispatch("patient/getTPriceHeaderCurrent");
    // this.$store.dispatch("patient/getPackets", {
    //     searchPacket : this.search_packet,
    //     current_page: this.current_page_packet,
    //     lastid: -1
    // })
  },
  data: () => ({
    // cpone
    search_corporate: "",
    // cpone
    menufilterdatestart: false,
    menufilterdateend: false,
    date: new Date().toISOString().substr(0, 10),
    search_company: "",
    search_doctor: "",
    is_loading: false,
    requiredcompany: false,
    requiredmou: false,
    requireddoctor: false,
    openprint: false,
    urlprint: "",
    clicks: 0,
    result: [],
    delay: 300,
    // show1: true,
    indeterminatex: false,
    headers: [
      {
        text: "EMAIL USER MCU",
        align: "center",
        sortable: false,
        width: "90%",
        class: "pl-2 pt-1 pb-1 pr-2 blue-grey text-xs-center white--text"
      },
      {
        text: "AKSI",
        align: "center",
        sortable: false,
        width: "10%",
        class: "pl-2 pt-1 pb-1 pr-2 blue-grey text-xs-center white--text"
      }
    ],
  }),
  computed: {
    mgm_mcuemailresult: {
      get() {
        return this.$store.state.patient.mgm_mcuemailresult
      },
      set(val) {
        this.$store.commit("patient/update_mgm_mcuemailresult", val)
      }
    },
    // cpone
    xgeneratepasswordby() {
      return this.$store.state.patient.generatepasswordby
    },
    selected_generatepasswordby: {
      get() {
        return this.$store.state.patient.selected_generatepasswordby
      },
      set(val) {
        this.$store.commit("patient/update_selected_generatepasswordby", val)
      }
    },
    reportresult: {
      get() {
        return this.$store.state.patient.reportresult
      },
      set(val) {
        this.$store.commit("patient/update_reportresult", val)
      }
    },
    show_delete: {
      get() {
        return this.$store.state.patient.show_delete
      },
      set(val) {
        this.$store.commit("patient/update_show_delete", val)
      }
    },
    bar_chx_allx: {
      get() {
        return this.$store.state.patient.bar_chx_allx
      },
      set(val) {
        this.$store.commit("patient/update_bar_chx_allx", val)
      }
    },
    xUserMculists() {
      return this.$store.state.patient.userMcuLists
    },
    dialogerror: {
      get() {
        return this.$store.state.patient.dialog_error;
      },
      set(val) {
        this.$store.commit("patient/update_dialog_error", val);
      },
    },
    msgerror() {
      return this.$store.state.patient.msg_error;
    },
    xtpriceheaderformCb() {
      return this.$store.state.patient.tpriceheaderformCb;
    },
    selected_tpriceheaderformCb: {
      get() {
        return this.$store.state.patient.selected_tpriceheaderformCb;
      },
      set(val) {
        this.$store.commit("patient/update_selected_tpriceheaderformCb", val);
      },
    },
    selected_detail_paketx: {
      get() {
        return this.$store.state.patient.selected_detail_paketx;
      },
      set(val) {
        this.$store.commit("patient/update_selected_detail_paketx", val);
      },
    },
    dialogconfirmationdetailpaket: {
      get() {
        return this.$store.state.patient.dialog_confirmation_paket;
      },
      set(val) {
        this.$store.commit("patient/update_dialog_confirmation_paket", val);
      },
    },
    xdetailpackets() {
      return this.$store.state.patient.detailpackets;
    },
    inp_Mgm_McuPicEmailValidate: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuPicEmailValidate;
      },
      set(val) {
        this.$store.commit("patient/update_inp_Mgm_McuPicEmailValidate", val);
      },
    },
    inp_Mgm_McuUserEmailValidate: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuUserEmailValidate;
      },
      set(val) {
        this.$store.commit("patient/update_inp_Mgm_McuUserEmailValidate", val);
      },
    },
    xshow1: {
      get() {
        return this.$store.state.patient.show1;
      },
      set(val) {
        this.$store.commit("patient/update_show1", val);
      },
    },
    xcorporates() {
      return this.$store.state.patient.corporates;
    },
    xcorporate: {
      get() {
        return this.$store.state.patient.corporate;
      },
      set(val) {
        this.$store.commit("patient/update_corporate", val);
        //console.log(val)
        this.$store.dispatch("patient/getemailresult", {
          Mgm_McuID: this.$store.state.patient.selected_mgmmcu ? this.$store.state.patient.selected_mgmmcu.Mgm_McuID : 0,
          corporate_id: val.id
        })
      },
    },
    xbranchCb() {
      return this.$store.state.patient.branchs;
    },
    selected_branchCb: {
      get() {
        return this.$store.state.patient.selected_branch;
      },
      set(val) {
        this.$store.commit("patient/update_selected_branch", val);
      },
    },
    xtemplatefisikCb() {
      return this.$store.state.patient.templateFisikCb;
    },
    selected_templateFisikCb: {
      get() {
        return this.$store.state.patient.selected_templateFisikCb;
      },
      set(val) {
        this.$store.commit("patient/update_selected_templateFisikCb", val);
      },
    },
    inp_Mgm_McuNote: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuNote;
      },
      set(val) {
        this.$store.commit("patient/update_inp_Mgm_McuNote", val);
      },
    },
    inp_Mgm_McuFlagRelasiBayarSendiri: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuFlagRelasiBayarSendiri;
      },
      set(val) {
        this.$store.commit(
          "patient/update_inp_Mgm_McuFlagRelasiBayarSendiri",
          val
        );
      },
    },
    inp_Mgm_McuBisaTambahPemeriksaan: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuBisaTambahPemeriksaan;
      },
      set(val) {
        this.$store.commit(
          "patient/update_inp_Mgm_McuBisaTambahPemeriksaan",
          val
        );
      },
    },
    inp_Mgm_McuLabel: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuLabel;
      },
      set(val) {
        this.$store.commit("patient/update_inp_Mgm_McuLabel", val);
      },
    },
    inp_Mgm_McuPicName: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuPicName;
      },
      set(val) {
        this.$store.commit("patient/update_inp_Mgm_McuPicName", val);
      },
    },
    inp_Mgm_McuPicEmail: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuPicEmail;
      },
      set(val) {
        this.$store.commit("patient/update_inp_Mgm_McuPicEmail", val);
      },
    },
    inp_Mgm_McuUserEmail: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuUserEmail;
      },
      set(val) {
        this.$store.commit("patient/update_inp_Mgm_McuUserEmail", val);
      },
    },
    inp_Mgm_McuPicPassword: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuPicPassword;
      },
      set(val) {
        this.$store.commit("patient/update_inp_Mgm_McuPicPassword", val);
      },
    },
    inp_Mgm_McuUserPassword: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuUserPassword;
      },
      set(val) {
        this.$store.commit("patient/update_inp_Mgm_McuUserPassword", val);
      },
    },
    inp_Mgm_McuTotalParticipant: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuTotalParticipant;
      },
      set(val) {
        this.$store.commit("patient/update_inp_Mgm_McuTotalParticipant", val);
      },
    },
    inp_Mgm_McuLowBackPainTampilSemua: {
      get() {
        return this.$store.state.patient.inp_Mgm_McuLowBackPainTampilSemua;
      },
      set(val) {
        this.$store.commit("patient/update_inp_Mgm_McuLowBackPainTampilSemua", val);
      },
    },
    // cpone
    current_page_test: {
      get() {
        return this.$store.state.patient.current_page_test;
      },
      set(val) {
        this.$store.commit("patient/update_current_page_test", val);
        var prm = this.default_mou;
        prm.search = this.search_test;
        prm.current_page = val;
        this.$store.dispatch("patient/getdatatests", prm);
      },
    },
    current_page_packet: {
      get() {
        return this.$store.state.patient.current_page_packet;
      },
      set(val) {
        this.$store.commit("patient/update_current_page_packet", val);
        // var prm = this.default_mou;
        // prm.T_PriceHeaderID = this.selected_tpriceheaderformCb.T_PriceHeaderID;
        // prm.search = this.search_packet;
        // prm.current_page = val;
        // this.$store.dispatch("patient/getdatapackets", prm);
        this.$store.dispatch("patient/getPackets", {
          T_PriceHeaderID: this.selected_tpriceheaderformCb.T_PriceHeaderID,
          searchPacket: this.search_packet,
          current_page: val,
          lastid: -1,
        });
      },
    },
    packets() {
      return this.$store.state.patient.packets;
    },
    tests() {
      return this.$store.state.patient.tests;
    },
    is_progress() {
      return this.$store.state.patient.is_progress;
    },
    total_patient_packet() {
      return this.$store.state.patient.total_patient_packet;
    },
    total_patient_test() {
      return this.$store.state.patient.total_patient_test;
    },
    search_test: {
      get() {
        return this.$store.state.patient.search_test;
      },
      set(val) {
        this.$store.commit("patient/update_search_test", val);
        this.$store.commit("patient/update_no_save", 1);
      },
    },
    search_packet: {
      get() {
        return this.$store.state.patient.search_packet;
      },
      set(val) {
        this.$store.commit("patient/update_search_packet", val);
        this.$store.commit("patient/update_no_save", 1);
      },
    },
    selected_packets: {
      get() {
        return this.$store.state.patient.selected_packets;
      },
      set(val) {
        this.$store.commit("patient/update_selected_packets", val);
      },
    },
    selected_tests: {
      get() {
        return this.$store.state.patient.selected_tests;
      },
      set(val) {
        this.$store.commit("patient/update_selected_tests", val);
      },
    },
    status() {
      return this.$store.state.patient.status;
    },
    deliveries: {
      get() {
        return this.$store.state.patient.deliveries;
      },
      set(val) {
        this.$store.commit("patient/update_deliveries", val);
      },
    },
    default_mou: {
      get() {
        return this.$store.state.patient.default_mou;
      },
      set(val) {
        this.$store.commit("patient/update_default_mou", val);

        this.$store.commit("patient/update_packets", []);
        this.$store.commit("patient/update_tests", []);
        this.$store.commit("patient/update_selected_packets", []);
        this.$store.commit("patient/update_selected_tests", []);
        this.$store.commit("patient/update_current_page_test", 1);
        this.$store.commit("patient/update_current_page_packet", 1);
        this.$store.commit("patient/update_total_patient_packet", 0);
        this.$store.commit("patient/update_total_patient_test", 0);
        var prm = val;
        prm.T_PriceHeaderID = this.selected_tpriceheaderformCb.T_PriceHeaderID;
        prm.current_page = 1;
        prm.search = "";
        // this.$store.dispatch("patient/getdatapackets", prm);
        this.$store.dispatch("patient/getPackets", {
          T_PriceHeaderID: this.selected_tpriceheaderformCb.T_PriceHeaderID,
          searchPacket: "",
          current_page: 1,
        });
        this.$store.dispatch("patient/getdatatests", prm);

        this.$store.dispatch("patient/getdeliveries", val);
      },
    },
    default_doctor: {
      get() {
        return this.$store.state.patient.default_doctor;
      },
      set(val) {
        this.$store.commit("patient/update_default_doctor", val);
        this.$store.commit("patient/update_doctor_address", val.xaddress);
        this.$store.commit("patient/update_default_doctor_address", {});
      },
    },
    default_doctor_address: {
      get() {
        return this.$store.state.patient.default_doctor_address;
      },
      set(val) {
        this.$store.commit("patient/update_default_doctor_address", val);
      },
    },
    picker_date: {
      get() {
        return this.$store.state.patient.promise_date;
      },
      set(val) {
        this.$store.commit("patient/update_promise_date", val);
      },
    },
    picker_time: {
      get() {
        return this.$store.state.patient.promise_time;
      },
      set(val) {
        this.$store.commit("patient/update_promise_time", val);
      },
    },
    doctor_address() {
      return this.$store.state.patient.doctor_address;
    },
    xseldoctors() {
      return this.$store.state.patient.selected_doctors;
    },
    xselmous() {
      return this.$store.state.patient.selected_mous;
    },
    xordercompanies() {
      return this.$store.state.patient.companies;
    },
    xordercompany: {
      get() {
        return this.$store.state.patient.company;
      },
      set(val) {
        this.$store.commit("patient/update_company", val);
        this.$store.dispatch(
          "patient/getmou",
          this.$store.state.patient.company
        );
      },
    },
    xdoctors() {
      return this.$store.state.patient.doctors;
    },
    xdoctor: {
      get() {
        return this.$store.state.patient.doctor;
      },
      set(val) {
        this.$store.commit("patient/update_doctor", val);
      },
    },
    filterComputedDateFormattedStart() {
      return this.formatDate(this.xdatestart);
    },
    filterComputedDateFormattedEnd() {
      return this.formatDate(this.xdateend);
    },
    dialogconfirmationdelete: {
      get() {
        return this.$store.state.patient.dialog_confirmation_delete;
      },
      set(val) {
        this.$store.commit("patient/update_dialog_confirmation_delete", val);
      },
    },
    msgconfirmationdelete() {
      return this.$store.state.patient.msg_confirmation_delete;
    },
    xact() {
      return this.$store.state.patient.act;
    },
    detail() {
      return this.$store.state.patient.selected_patient;
    },
    xdatestart: {
      get() {
        return this.$store.state.patient.start_date;
      },
      set(val) {
        this.$store.commit("patient/update_start_date", val);
        //this.searchTransaction()
      },
    },
    xdateend: {
      get() {
        return this.$store.state.patient.end_date;
      },
      set(val) {
        this.$store.commit("patient/update_end_date", val);
        //this.searchTransaction()
      },
    },
    xmous() {
      return this.$store.state.patient.mous;
    },
    xmou: {
      get() {
        return this.$store.state.patient.mou;
      },
      set(val) {
        this.$store.commit("patient/update_mou", val);
        this.$store.commit("patient/update_no_save", 1);
      },
    },
  },
  methods: {
    // cpone
    // validasiCreateSSMou(){
    //     this.$store.dispatch("patient/createSSMou",{
    //         T_PriceHeaderID: this.selected_tpriceheaderformCb.T_PriceHeaderID
    //     })
    // },
    changeEmailResult(value) {
      console.log("cek value", value)
      if (value == 'N') {
        if (this.mgm_mcuemailresult.Mgm_McuEmailResultValue == '')
          this.mgm_mcuemailresult.Mgm_McuEmailResultValue = this.mgm_mcuemailresult.CorporatePICEmail == '' ? this.mgm_mcuemailresult.CorporateEmail : this.mgm_mcuemailresult.CorporatePICEmail
      } else {
        this.mgm_mcuemailresult.Mgm_McuEmailResultValue = ''
      }

    },
    changeCbxAllX(value) {
      console.log("cek value", value)
      this.show_delete = false
      var arr = this.xUserMculists
      this.indeterminatex = false
      // this.btn_hide = true
      // var filtered_arr =  _.filter(arr, function(o) { return o.status === 'N' })
      arr.forEach((el) => { el.chex = value })
      var selected = _.filter(arr, function (o) { return o.chex })
      if (selected.length > 0) {
        this.show_delete = true
      }
    },
    checkTopX() {
      this.show_delete = false
      var barcodes = this.xUserMculists
      var selected = _.filter(barcodes, function (o) { return o.chex; })
      this.bar_chx_allx = false
      this.indeterminatex = false
      if (selected.length > 0 && barcodes.length === selected.length) {
        this.bar_chx_allx = true
        this.indeterminatex = false
        this.show_delete = true
      }
      if (selected.length > 0 && barcodes.length > selected.length) {
        this.bar_chx_allx = false
        this.indeterminatex = true
        this.show_delete = true
      }

    },
    deleteUserMcu() {
      var arr = this.$store.state.patient.userMcuLists
      var selected = _.filter(arr, function (o) { return o.chex })
      var deleted = this.$store.state.patient.deleted_usermcus
      selected.forEach(function (value, index) {
        if (parseInt(value.Mgm_McuUserID) > 0) {
          var idx_del = _.findIndex(deleted, itemx => parseInt(itemx.Mgm_McuUserID) === parseInt(value.Mgm_McuUserID))
          if (idx_del === -1)
            deleted.push(value)
        }
      })

      this.$store.commit("patient/update_deleted_usermcus", deleted)
      this.show_delete = false
    },
    changePriceHeaderForm(selectedItem) {
      console.log("Selected item price header:", selectedItem);
      this.$store.commit("patient/update_selected_tpriceheaderformCb", {
        T_PriceHeaderID: selectedItem.T_PriceHeaderID,
        T_PriceHeaderName: selectedItem.T_PriceHeaderName,
        T_PriceHeaderStartDate: selectedItem.T_PriceHeaderStartDate,
        T_PriceHeaderEndDate: selectedItem.T_PriceHeaderEndDate,
        T_PriceHeaderIsActive: selectedItem.T_PriceHeaderIsActive,
        T_PriceHeaderUserID: selectedItem.T_PriceHeaderUserID,
        T_PriceHeaderCreated: selectedItem.T_PriceHeaderCreated,
        T_PriceHeaderCraetdUserID: selectedItem.T_PriceHeaderCraetdUserID,
        T_PriceHeaderLastUpdated: selectedItem.T_PriceHeaderLastUpdated,
        T_PriceHeaderLastUpdatedUserID:
          selectedItem.T_PriceHeaderLastUpdatedUserID,
        T_PriceHeaderDeleted: selectedItem.T_PriceHeaderDeleted,
        T_PriceHeaderDeletedUserID: selectedItem.T_PriceHeaderDeletedUserID,
      });
      this.$store.commit("patient/update_current_page_packet", 1);

      this.$store.dispatch("patient/getPackets", {
        T_PriceHeaderID: this.selected_tpriceheaderformCb.T_PriceHeaderID,
        searchPacket: this.search_packet,
        current_page: 1,
        lastid: -1,
      });
    },
    closeDialogError() {
      this.$store.commit("patient/update_dialog_error", false);
    },
    convertMoney(money) {
      return one_money(money);
    },
    getDetailPacket(row) {
      // this.clicks++
      // if(this.clicks === 1) {
      //     var self = this
      //     this.timer = setTimeout(function() {
      //         self.result.push(event.type);
      //         self.clicks = 0
      //     }, this.delay);
      //     // this.clicks = 0;
      // } else{
      //     console.log('get detail packet',row)
      //     clearTimeout(this.timer);
      //     this.result.push('dblclick');
      //     this.clicks = 0;

      //     // dispatch

      // }

      console.log("detail", row);
      this.$store.commit("patient/update_selected_detail_paketx", row);

      this.$store.dispatch("patient/getDetailPacketByID", {
        T_PacketID: row.T_PacketID,
      });
    },
    validateEmail() {
      // this.$refs.form.validate();
      console.log("value", this.inp_Mgm_McuPicEmail);
      const value = this.inp_Mgm_McuPicEmail;

      if (value.length > 0) {
        const pattern =
          /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        // return pattern.test(value) || 'Invalid e-mail.';
        if (!pattern.test(value)) {
          this.$store.commit(
            "patient/update_inp_Mgm_McuPicEmailValidate",
            "Email Tidak Valid"
          );
          console.log("not valid email");
        } else {
          this.$store.commit("patient/update_inp_Mgm_McuPicEmailValidate", "");
          console.log("valid email");
        }
      }
    },
    validateUserEmail() {
      // this.$refs.form.validate();
      console.log("value", this.inp_Mgm_McuUserEmail);
      const value = this.inp_Mgm_McuUserEmail;

      if (value.length > 0) {
        const pattern =
          /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        // return pattern.test(value) || 'Invalid e-mail.';
        if (!pattern.test(value)) {
          this.$store.commit(
            "patient/update_inp_Mgm_McuUserEmailValidate",
            "Email Tidak Valid"
          );
          console.log("not valid email");
        } else {
          this.$store.commit("patient/update_inp_Mgm_McuUserEmailValidate", "");
          console.log("valid email");
        }
      }
    },
    validateNumber() {
      if (this.inp_Mgm_McuTotalParticipant < 0) {
        this.inp_Mgm_McuTotalParticipant = 0;
      }
    },
    thr_search_corporate: _.debounce(function () {
      console.log(this.search_corporate);
      this.$store.dispatch("patient/searchcorporate", {
        search: this.search_corporate,
      });
    }, 2000),
    deleteTempUserMcuRow(idx) {
      this.$store.dispatch("patient/removeUserMcuTemp", idx)
    },
    resetUserMcu() {
      this.$store.commit("patient/update_inp_Mgm_McuUserEmail", "");
      this.$store.commit("patient/update_inp_Mgm_McuUserPassword", "");
    },
    saveUserMcu() {
      this.$store.commit("patient/update_errors", [])
      var errors = this.$store.state.patient.errors

      if (_.isEmpty(this.inp_Mgm_McuUserEmail)) {
        errors.push("requireusermcuemail")
      }
      if (_.isEmpty(this.inp_Mgm_McuUserPassword)) {
        errors.push("requireusermcupassword")
      }

      if (errors.length === 0) {
        let arrTempUserMcu = this.xUserMculists

        this.$store.commit("patient/update_usermcuid", 0)

        arrTempUserMcu.push({
          Mgm_McuUserID: this.$store.state.patient.usermcuid,
          Mgm_McuUserEmail: this.inp_Mgm_McuUserEmail,
          Mgm_McuUserPassword: this.inp_Mgm_McuUserPassword
        })

        if (this.xUserMculists.length > 0) {
          this.resetUserMcu()
        }
      }

    },

    savesetupX() {
      var go_save = true;
      if (go_save) {
        // var prm = {
        //             xid:this.$store.state.patient.xid,
        //             act:this.$store.state.patient.act,
        //             startdate:this.$store.state.patient.start_date,
        //             enddate:this.$store.state.patient.end_date,
        //             company : this.$store.state.patient.company,
        //             mous:this.$store.state.patient.selected_mous,
        //             doctors:this.$store.state.patient.selected_doctors,
        //             promise_date:this.$store.state.patient.promise_date,
        //             promise_time:this.$store.state.patient.promise_time,
        //             default_mou:this.$store.state.patient.default_mou,
        //             default_doctor:this.$store.state.patient.default_doctor,
        //             default_doctor_address:this.$store.state.patient.default_doctor_address,
        //             deliveries:this.$store.state.patient.deliveries,
        //             selected_packets:this.$store.state.patient.selected_packets,
        //             selected_tests:this.$store.state.patient.selected_tests,
        //         }
        // this.$store.dispatch("patient/savesetup",prm)

        var prm = {
          Mgm_McuGeneratePasswordBY: this.selected_generatepasswordby.generatepasswordbycode,
          Mgm_McuReportHasil: this.reportresult,
          arrUserMcu: this.xUserMculists,
          deleted_usermcus: this.$store.state.patient.deleted_usermcus,
          xid: this.$store.state.patient.xid,
          act: this.$store.state.patient.act,
          Mgm_McuLabel: this.$store.state.patient.inp_Mgm_McuLabel,
          Mgm_McuPicName: this.$store.state.patient.inp_Mgm_McuPicName,
          Mgm_McuCorporateID: this.$store.state.patient.corporate,
          Mgm_McuStartDate: this.$store.state.patient.start_date,
          Mgm_McuEndDate: this.$store.state.patient.end_date,
          Mgm_McuFlagRelasiBayarSendiri:
            this.$store.state.patient.inp_Mgm_McuFlagRelasiBayarSendiri,
          Mgm_McuBisaTambahPemeriksaan:
            this.$store.state.patient.inp_Mgm_McuBisaTambahPemeriksaan,
          Mgm_McuNote: this.$store.state.patient.inp_Mgm_McuNote,
          selected_packets: this.$store.state.patient.selected_packets,
          Mgm_McuTemplateFisikTemplateMappingID:
            this.$store.state.patient.selected_templateFisikCb,
          Mgm_McuPicEmail: this.$store.state.patient.inp_Mgm_McuPicEmail,
          Mgm_McuPicPassword: this.$store.state.patient.inp_Mgm_McuPicPassword,
          Mgm_McuLowBackPainTampilSemua: this.$store.state.patient.inp_Mgm_McuLowBackPainTampilSemua,
          Mgm_McuTotalParticipant:
            this.$store.state.patient.inp_Mgm_McuTotalParticipant,
          Mgm_McuT_PriceHeaderID:
            this.$store.state.patient.selected_tpriceheaderformCb
              .T_PriceHeaderID,
          Mgm_McuM_BranchID:
            this.$store.state.patient.selected_branch.M_BranchID,
          search: this.$store.state.patient.search_mgmmcu,
          current_page: this.$store.state.patient.current_page,
          lastid: -1,
          mgm_mcuemailresult: this.$store.state.patient.mgm_mcuemailresult
        };

        console.log("inputan simpan or edit", prm);
        this.$store.dispatch("patient/savesetupv0", prm);
      }
    },
    // cpone
    checkNatTest(item) {
      var now_natest = item.nat_test;
      var rtn = true;
      var selected_packets = this.$store.state.patient.selected_packets;
      var selected_tests = this.$store.state.patient.selected_tests;
      selected_packets.forEach(function (entry) {
        var nat_test = entry.nat_test;
        now_natest.forEach(function (itemnattest) {
          var idx = _.findIndex(nat_test, function (o) {
            return o == itemnattest;
          });
          if (idx > -1) rtn = false;
        });
      });
      selected_tests.forEach(function (entry) {
        var nat_test = entry.nat_test;
        now_natest.forEach(function (itemnattest) {
          var idx = _.findIndex(nat_test, function (o) {
            return o == itemnattest;
          });
          if (idx > -1) rtn = false;
        });
      });
      return rtn;
    },
    testExist(item) {
      var selected_tests = this.$store.state.patient.selected_tests;
      var idx = _.findIndex(selected_tests, function (o) {
        return parseInt(o.id) === parseInt(item.id);
      });
      if (idx === -1) {
        return true;
      } else {
        return false;
      }
    },
    addToTests(item) {
      var selected_tests = this.$store.state.patient.selected_tests;
      selected_tests.push(item);
    },
    removeFromTests(item) {
      var selected_tests = this.$store.state.patient.selected_tests;
      var idx = _.findIndex(selected_tests, function (o) {
        return parseInt(o.id) === parseInt(item.id);
      });
      selected_tests.splice(idx, 1);
    },
    searchTest() {
      var prm = this.default_mou;
      prm.search = this.search_test;
      prm.current_page = 1;
      this.$store.commit("patient/update_current_page_test", 1);
      this.$store.dispatch("patient/getdatatests", prm);
    },
    packetExist(item) {
      var selected_packets = this.$store.state.patient.selected_packets;
      var idx = _.findIndex(selected_packets, function (o) {
        return parseInt(o.id) === parseInt(item.id);
      });
      if (idx === -1) {
        return true;
      } else {
        return false;
      }
    },
    addToPackets(item) {
      var selected_packets = this.$store.state.patient.selected_packets;
      selected_packets.push(item);
    },
    removeFromPackets(item) {
      var selected_packets = this.$store.state.patient.selected_packets;
      var idx = _.findIndex(selected_packets, function (o) {
        return parseInt(o.id) === parseInt(item.id);
      });
      selected_packets.splice(idx, 1);
    },
    searchPacket() {
      // var prm = this.default_mou
      // prm.search = this.search_packet
      // prm.current_page = 1
      this.$store.commit("patient/update_current_page_packet", 1);
      // this.$store.dispatch("patient/getdatapackets", prm)
      this.$store.dispatch("patient/getPackets", {
        T_PriceHeaderID: this.selected_tpriceheaderformCb.T_PriceHeaderID,
        searchPacket: this.search_packet,
        current_page: this.current_page_packet,
        lastid: -1,
      });
    },
    thr_search_company: _.debounce(function () {
      console.log(this.search_company);
      this.$store.dispatch("patient/searchcompany", {
        search: this.search_company,
      });
    }, 2000),
    openPrint(item) {
      this.urlprint =
        "/birt/run?__report=report/one/rekap/rpt_r_073.rptdesign&__format=pdf&PMouID=" +
        item.id +
        "&username=admin";
      this.openprint = true;
    },
    changeBoxRight(value, idx) {
      var deliveries = this.$store.state.patient.deliveries;
      console.log(deliveries);
      deliveries[idx].chex = value.chex === "N" ? "Y" : "N";
      console.log(deliveries[idx].chex);
      this.$store.commit("patient/update_deliveries", deliveries);
    },
    reHTMLAddress(entry) {
      var rtn = "";
      if (entry) {
        var perpart = entry.split("^");
        rtn += "<p class='mb-0' style='font-size:12px'>" + perpart[0] + "</p>";
        if (perpart[1])
          rtn +=
            "<p class='mb-0' style='font-size:12px'>" + perpart[1] + "</p>";
      }

      return rtn;
    },
    getColorFont(value, type) {
      var xcolor = "black--text";
      if (value.chex === "Y") {
        xcolor = "teal--text";
      }

      return xcolor;
    },
    downloadxapp() {
      var start = Date.now();
      location.replace("/install-mcu.zip?tm=" + start);
    },
    delmou(row) {
      var arr = this.$store.state.patient.selected_mous;
      idx = _.findIndex(arr, row);
      arr.splice(idx, 1);
      this.$store.commit("patient/update_default_mou", {});

      var arr_mous = this.$store.state.patient.mous;
      arr_mous.push(row);
      this.$store.commit("patient/update_mous", arr_mous);
    },
    deldoctor(row) {
      var arr = this.$store.state.patient.selected_doctors;
      idx = _.findIndex(arr, row);
      arr.splice(idx, 1);

      var newx = this.$store.state.patient.selected_doctors;
      if (newx.length === 0) {
        this.$store.commit("patient/update_default_doctor", {});
      }
    },
    savesetup() {
      var go_save = true;
      if (go_save) {
        var prm = {
          xid: this.$store.state.patient.xid,
          act: this.$store.state.patient.act,
          startdate: this.$store.state.patient.start_date,
          enddate: this.$store.state.patient.end_date,
          company: this.$store.state.patient.company,
          mous: this.$store.state.patient.selected_mous,
          doctors: this.$store.state.patient.selected_doctors,
          promise_date: this.$store.state.patient.promise_date,
          promise_time: this.$store.state.patient.promise_time,
          default_mou: this.$store.state.patient.default_mou,
          default_doctor: this.$store.state.patient.default_doctor,
          default_doctor_address:
            this.$store.state.patient.default_doctor_address,
          deliveries: this.$store.state.patient.deliveries,
          selected_packets: this.$store.state.patient.selected_packets,
          selected_tests: this.$store.state.patient.selected_tests,
        };
        this.$store.dispatch("patient/savesetup", prm);
      }
    },
    adddoctor() {
      var selected = this.$store.state.patient.doctor;
      var arr = this.$store.state.patient.doctors;
      var xsel = this.$store.state.patient.selected_doctors;
      xsel.push(selected);
      this.$store.commit("patient/update_selected_doctors", xsel);
      this.$store.commit("patient/update_doctors", []);
      this.$store.commit("patient/update_doctor", {});
    },
    addmou() {
      var selected = this.$store.state.patient.mou;
      var arr = this.$store.state.patient.mous;
      var xsel = this.$store.state.patient.selected_mous;
      xsel.push(selected);
      this.$store.commit("patient/update_selected_mous", xsel);
      var filtered = arr.filter(
        (o1) => xsel.filter((o2) => o2.id === o1.id).length === 0
      );
      this.$store.commit("patient/update_mous", filtered);
      this.$store.commit("patient/update_mou", {});
    },
    thr_search_doctor: _.debounce(function () {
      //console.log('thr doctor')
      this.$store.dispatch("patient/searchdoctor", this.search_doctor);
    }, 2000),
    thr_search_company: _.debounce(function () {
      console.log(this.search_company);
      this.$store.dispatch("patient/searchcompany", {
        search: this.search_company,
      });
    }, 2000),
    formatDate(date) {
      if (!date) return null;

      const [year, month, day] = date.split("-");
      return `${day}-${month}-${year}`;
    },
    deFormatedDate(date) {
      if (!date) return null;

      const [day, month, year] = date.split("-");
      return `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`;
    },
    checkError(value) {
      var errors = this.$store.state.patient.errors;
      if (errors.includes(value)) {
        return true;
      } else {
        return false;
      }
    },
    saveData() {
      this.$store.commit("patient/update_errors", []);
      var errors = this.$store.state.patient.errors;
      var aDOB = moment(this.xdob, "DD-MM-YYYY", true);
      console.log(this.xdob);
      console.log(aDOB);
      var isValidDOB = aDOB.isValid();
      if (!isValidDOB) {
        errors.push("wrongformatdob");
      }
      if (this.xpatientname === "") {
        errors.push("requirename");
      }
      if (this.xdob === "") {
        errors.push("requiredob");
      }
      if (_.isEmpty(this.xsex)) {
        errors.push("requiresex");
      }
      if (_.isEmpty(this.xtitle)) {
        errors.push("requiretitle");
      }
      if (errors.length === 0) {
        var prm = {};
        prm.M_PatientID =
          this.$store.state.patient.selected_patient.M_PatientID;
        prm.M_PatientM_TitleID =
          this.$store.state.patient.selected_title.M_TitleID;
        prm.M_PatientPrefix = this.xpatientprefix;
        prm.M_PatientName = this.xpatientname;
        prm.M_PatientSuffix = this.xpatientsuffix;
        prm.M_PatientDOB = this.xdob;
        prm.M_PatientM_SexID = this.$store.state.patient.selected_sex.M_SexID;
        prm.M_PatientM_ReligionID =
          this.$store.state.patient.selected_religion.M_ReligionID;
        prm.M_PatientEmail = this.xemail;
        prm.M_PatientPOB = this.xpob;
        prm.M_PatientHP = this.xhp;
        prm.M_PatientPhone = this.xphone;
        prm.M_PatientM_IdTypeID =
          this.$store.state.patient.selected_kartuidentitas.M_IdTypeID;
        prm.M_PatientIDNumber = this.xnoidentitas;
        prm.M_PatientNote = this.xnote;
        prm.M_PatientNIK = this.xnik;
        prm.M_PatientJabatan = this.xjabatan;
        prm.M_PatientKedudukan = this.xkedudukan;
        prm.M_PatientPJ = this.xpj;
        prm.M_PatientLocation = this.xlocation;
        prm.M_PatientJob = this.xjob;
        this.$store.dispatch("patient/save", prm);
      }
    },
    saveNewPatient() {
      this.$store.commit("patient/update_errors", []);
      var errors = this.$store.state.patient.errors;
      var aDOB = moment(this.xdob, "DD-MM-YYYY", true);
      console.log(this.xdob);
      console.log(aDOB);
      var isValidDOB = aDOB.isValid();
      if (!isValidDOB) {
        errors.push("wrongformatdob");
      }
      if (this.xpatientname === "") {
        errors.push("requirename");
      }
      if (this.xdob === "") {
        errors.push("requiredob");
      }
      if (_.isEmpty(this.xsex)) {
        errors.push("requiresex");
      }
      if (_.isEmpty(this.xtitle)) {
        errors.push("requiretitle");
      }
      if (errors.length === 0) {
        var prm = {};
        prm.M_PatientID = 0;
        prm.M_PatientM_TitleID =
          this.$store.state.patient.selected_title.M_TitleID;
        prm.M_PatientPrefix = this.xpatientprefix;
        prm.M_PatientName = this.xpatientname;
        prm.M_PatientSuffix = this.xpatientsuffix;
        prm.M_PatientDOB = this.xdob;
        prm.M_PatientM_SexID = this.$store.state.patient.selected_sex.M_SexID;
        prm.M_PatientM_ReligionID =
          this.$store.state.patient.selected_religion.M_ReligionID;
        prm.M_PatientEmail = this.xemail;
        prm.M_PatientPOB = this.xpob;
        prm.M_PatientHP = this.xhp;
        prm.M_PatientPhone = this.xphone;
        prm.M_PatientM_IdTypeID =
          this.$store.state.patient.selected_kartuidentitas.M_IdTypeID;
        prm.M_PatientIDNumber = this.xnoidentitas;
        prm.M_PatientNote = this.xnote;
        prm.M_PatientNIK = this.xnik;
        prm.M_PatientJabatan = this.xjabatan;
        prm.M_PatientKedudukan = this.xkedudukan;
        prm.M_PatientPJ = this.xpj;
        prm.M_PatientLocation = this.xlocation;
        prm.M_PatientJob = this.xjob;
        this.$store.dispatch("patient/newpatient", prm);
      }
    },
    deleteData() {
      let msg = "Yakin, akan menghapus data pasien " + this.xpatientname + " ?";
      this.$store.commit("patient/update_msg_confirmation_delete", msg);
      this.$store.commit("patient/update_dialog_confirmation_delete", true);
    },
    doDeleteData() {
      var prm = {};
      prm.id = this.$store.state.patient.selected_mgmmcu.Mgm_McuID;
      prm.code = this.$store.state.patient.selected_mgmmcu.Mgm_McuNumber;
      console.log(prm);
      this.$store.dispatch("patient/deletev0", prm);
    },
  },
  watch: {
    // cpone
    search_corporate(val, old) {
      //console.log(val)
      if (val == old) return;
      if (!val) return;
      if (val.length < 1) return;
      if (this.$store.state.patient.update_autocomplete_status == 1) return;
      this.thr_search_corporate();
    },
    // cpone
    search_doctor(val, old) {
      console.log(val);
      if (val == old) return;
      if (!val) return;
      if (val.length < 1) return;
      if (this.$store.state.patient.update_autocomplete_status == 1) return;
      this.thr_search_doctor();
    },
    search_company(val, old) {
      //console.log(val)
      if (val == old) return;
      if (!val) return;
      if (val.length < 1) return;
      if (this.$store.state.patient.update_autocomplete_status == 1) return;
      this.thr_search_company();
    },
  },
};
</script>
