<template>
    <PopupWrapper>
        <div class="popup-image">
            <span class="emoji">{{ emoji }}</span>
        </div>

        <PopupContent class="content">
            <h1 v-if="title" class="text-2xl font-bold max-w-sm mx-auto">{{ title }}</h1>
            <p v-if="message" class="message">{{ message }}</p>
        </PopupContent>

        <PopupActions>
            <ButtonBase
                    @click.native="closePopup"
                    button-style="secondary"
                    class="w-full"
            >{{ $t('global.cancel') }}
            </ButtonBase>
            <ButtonBase
                    @click.native="confirm"
                    :button-style="buttonColor"
                    class="w-full"
            >{{ $t('global.confirm_action') }}
            </ButtonBase>
        </PopupActions>
    </PopupWrapper>
</template>

<script>
    import PopupWrapper from '/resources/js/components/Others/Popup/PopupWrapper'
    import PopupActions from '/resources/js/components/Others/Popup/PopupActions'
    import PopupContent from '/resources/js/components/Others/Popup/PopupContent'
    import ButtonBase from '/resources/js/components/FilesView/ButtonBase'
    import {events} from '/resources/js/bus'

    export default {
        name: 'ConfirmPopup',
        components: {
            PopupWrapper,
            PopupActions,
            PopupContent,
            ButtonBase,
        },
        data() {
            return {
                confirmationData: [],
                message: undefined,
                title: undefined,
                emoji: undefined,
                buttonColor: undefined,
            }
        },
        methods: {
            closePopup() {
                events.$emit('popup:close')
            },
            confirm() {
                // Close popup
                events.$emit('popup:close')

                // Confirmation popup
                events.$emit('action:confirmed', this.confirmationData)

                // Clear confirmation data
                this.confirmationData = []
            }
        },
        mounted() {
            // Show confirm
            events.$on('confirm:open', args => {
                this.title = args.title
                this.message = args.message
                this.emoji = '🤔'
                this.confirmationData = args.action
                this.buttonColor = 'danger'

                if (args.buttonColor) {
                    this.buttonColor = args.buttonColor
                }
            })
        }
    }
</script>

<style scoped lang="scss">
    @import '/resources/sass/vuefilemanager/_variables';
    @import '/resources/sass/vuefilemanager/_mixins';

    .popup-image {
        padding-top: 20px;
        text-align: center;
        margin-bottom: 20px;

        .emoji {
            @include font-size(56);
            line-height: 1;
        }
    }

    .content {
        text-align: center;
        padding-bottom: 10px;
        padding-left: 20px;
        padding-right: 20px;

        .message {
            @include font-size(16);
            color: #333;
            margin-top: 5px;
        }
    }

    @media only screen and (max-width: 690px){
        .content {
            top: 110px;
        }
    }

    .dark {

        .content {
            .title {
                color: $dark_mode_text_primary;
            }

            .message {
                color: $dark_mode_text_secondary;
            }
        }
    }
</style>
