<template>
    <view class="simple-share-popup">
        <cm-popup ref="sharePopup" type="bottom" :safe-area="safeArea">
            <!-- 操作栏 -->
            <view class="share-popup__control" @click.stop>
                <view class="share-popup__slot"><slot></slot></view>
                <view class="share-popup__row share-popup__items">
                    <button
                        open-type="share"
                        class="share-popup__item share-popup__button share-popup__default"
                        @click="onClick('share')"
                    >
                        <view class="share-popup__icon"><image :src="baseUrl + 'icon-share-wechat.png'"></image></view>
                        <text class="share-popup__label">分享给好友</text>
                    </button>
                    <view class="share-popup__item share-popup__button" @click="onClick('create-poster')">
                        <view class="share-popup__icon"><image :src="baseUrl + 'icon-poster.png'"></image></view>
                        <text class="share-popup__label">生成海报</text>
                    </view>
                </view>
                <view class="share-popup__row"><view class="share-popup__cancel" @click.stop="close">取消</view></view>
            </view>
        </cm-popup>
    </view>
</template>
<script>
    import cmPopup from '../uni-popup/uni-popup.vue'
export default {
    props: {
        baseUrl: {
            type: String,
            default: 'https://static.caimei365.com/app/mini-hehe/icon/'
        },
        safeArea: {
            type: Boolean,
            default: true
        }
    },
    components: {
        cmPopup
    },
    methods: {
        open() {
            this.$refs.sharePopup.open()
            this.$emit('open')
        },
        close() {
            this.$refs.sharePopup.close()
            this.$emit('close')
        },
        onClick(type) {
            this.$emit('click', { type })
        }
    }
}
</script>

<style lang="scss" scoped>
.simple-share-popup {
    .share-popup__control {
        width: 100%;
        background-color: #fff;
        border-radius: 16rpx 16rpx 0 0;
        padding-top: 40rpx;

        &.share-popup__no__safeArea {
            transform: translateY(34px);
        }

        &::after {
            content: '';
            position: absolute;
            width: 100%;
            height: 38px;
            bottom: -38px;
            background-color: #fff;
        }

        .share-popup__row {
            display: flex;
            justify-content: space-evenly;
            align-items: center;
        }

        .share-popup__items {
            padding-bottom: 40rpx;
        }

        .share-popup__button {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;

            &.share-popup__default {
                line-height: inherit;
                padding: 0;
                margin: 0;
                border: 0;
                background: transparent;
                &::after {
                    border: 0;
                }
            }

            .share-popup__icon {
                display: flex;
                justify-content: center;
                align-items: center;
                width: 100rpx;
                height: 100rpx;
                border-radius: 50%;
                background-color: #f7f7f7;

                image {
                    width: 64rpx;
                    height: 64rpx;
                }
            }

            .share-popup__label {
                font-size: 26rpx;
                color: #333;
                margin-top: 16rpx;
            }
        }

        .share-popup__cancel {
            width: 100%;
            padding: 32rpx 0;
            border-top: 1rpx solid #e1e1e1;
            font-size: 28rpx;
            color: #666;
            font-weight: bold;
            text-align: center;
        }
    }
}
</style>
