<template>
    <div class="content-wrapper">

        <app-page-top-section :title="$t('groups')">

          <!--  <div class="dropdown d-inline-block btn-dropdown">
                <button class="btn btn-success dropdown-toggle ml-0 mr-2"
                        aria-expanded="false"
                        aria-haspopup="true"
                        data-toggle="dropdown"
                        type="button">
                    {{ $t('action') }}
                </button>
                <div class="dropdown-menu">
                    <a class="dropdown-item d-flex align-items-center p-3" v-bind:href="PRODUCT_GROUP_IMPORT_PAGE">
                        <app-icon class="size-15 mr-2" name="upload"/>
                        {{ $t('import_group') }}
                    </a>
                    <a class="dropdown-item d-flex align-items-center p-3" href="#" @click="exportGroups">
                        <app-icon class="size-15 mr-2" name="download"/>
                        {{ $t('export_group') }}
                    </a>
                </div>
            </div>-->

            <app-default-button
                v-if="this.$can('create_groups')"
                :title="$addLabel('group')"
                @click="openModal()"/>

        </app-page-top-section>



        <app-table
            id="group-table"
            :options="options"
            @action="triggerAction"
        />

        <app-group-modal
            v-if="isModalActive"
            v-model="isModalActive"
            :selected-url="selectedUrl"
            @close="isModalActive = false"
        />

        <app-confirmation-modal
            v-if="confirmationModalActive"
            icon="trash-2"
            modal-id="app-confirmation-modal"
            @cancelled="cancelled"
            @confirmed="confirmed('group-table')"
        />
    </div>
</template>

<script>
import HelperMixin from "../../../../../common/Mixin/Global/HelperMixin";
import GroupMixin from "../../../Mixins/GroupMixin";
import {EXPORT_GROUPS, GROUPS, PRODUCT_GROUP_IMPORT_PAGE} from "../../../../Config/ApiUrl-CP";

export default {
    name: "Group",
    mixins: [HelperMixin, GroupMixin],
    data() {
        return {
            isModalActive: false,
            selectedUrl: '',
            PRODUCT_GROUP_IMPORT_PAGE
        }
    },
    methods: {
        triggerAction(row, action, active) {
            if (action.name === 'edit') {
                this.selectedUrl = `${GROUPS}/${row.id}`;
                this.isModalActive = true;
            } else {
                this.getAction(row, action, active)
            }
        },
        openModal() {
            this.isModalActive = true;
            this.selectedUrl = ''
        },
      exportGroups(){
          window.location = EXPORT_GROUPS;
      }
    }
}
</script>