<template>
  <div class="q-ma-sm">
    <div class="text-center">
      <q-spinner
        v-if="!loadpage"
        color="primary"
        size="3em"
        :thickness="2"
      />
    </div>
    <div
      v-if="loadpage"
      class="panel"
    >
      <!--<div class="text-h6 text-bold text-blue text-center">Cerca un Titolo:</div>-->
      <div
        class="col"
        v-for="(item, index) in searchList"
        :key="index"
      >
        <CMySelect
          v-if="item.type === costanti.FieldType.select || item.type === costanti.FieldType.select_by_server"
          :col="fieldsTable.getColByColumns(mycolumns, item.key)"
          :label="item.value && item.value._id > 0 ? undefined : labelcombo(item)"
          v-model:value="item.value"
          v-model:arrvalue="item.arrvalue"
          @update:arrvalue="updateproductmodif"
          :addall="item.addall"
          :addnone="item.addnone"
          :focus="focus"
          :addlast="true"
          :tablesel="item.type === costanti.FieldType.select_by_server ? item.tablesel : ''"
          :pickup="item.type === costanti.FieldType.select_by_server"
          color="primary"
          myclass=""
          :icon_alternative="item.icon"
          :optval="fieldsTable.getKeyByTable(item.table)"
          :optlab="item.collabel"
          :options="valoriopt(item, false)"
          :filter="item.filter"
          :filter_extra="item.filter_extra"
          :useinput="item.useinput && item.type !== costanti.FieldType.select_by_server"
          :dense="item.dense"
          @searchOnGM="searchOnGM"
          @clear="
            item.value = '';
            myproduct = null;
            saveSearch();
          "
        >
        </CMySelect>
      </div>

      <div
        v-if="myproduct?._id && optcatalogo.arrSchede?.length > 0"
        class="row justify-center"
        style="text-align: center"
      >
        <CContainerCatalogoCard
          :id="myproduct._id"
          :product="myproduct"
          :complete="false"
          :cosa="0"
          v-model="optcatalogo"
          :idPage="idPage"
          :options="{
            show_edit_book: tools.isEditor(),
          }"
          @selauthor="selauthor"
          :scheda="optcatalogo.arrSchede[0].scheda"
          @updateproductmodif="updateproductmodif"
        />
      </div>
    </div>
    <div class="column text-center">
      <div class="row justify-center q-ma-md">
        <div v-if="visu === shared_consts.VISU_SEARCHPROD_MODE.INSERT">
          <q-btn
            rounded
            class="q-ma-sm"
            color="secondary"
            icon="fas fa-plus"
            label="Inserisci"
            @click="insertProd"
          ></q-btn>
          <!-- Button Close window -->
          <q-btn
            rounded
            class="q-ma-sm"
            color="primary"
            icon="fas fa-times-circle"
            label="Chiudi"
            @click="clickClose"
          ></q-btn>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" src="./CSearchProduct.ts"></script>

<style lang="scss">
@import '../../views/ecommerce/catalogo/catalogo.scss';
</style>
