<style>
    .ListRowCard {
        margin-bottom: 5px;
    }
</style>

<div id="MainView">

</div>



<script>
    defaultBackOnclick = null;
    try {
        currentData = @json($current_data);
    } catch (error) {
        currentData = null;
    }


    LoadDataPageFunc = {};
    LoadDataPageFunc.PageTitle = 'Manage Product';
    LoadDataPageFunc.pageName = 'ManageProductAdmin';
    LoadDataPageFunc.MainDetailsURL = '';
    LoadDataPageFunc.Details = {};
    LoadDataPageFunc.Settings = {};

    LoadDataPageFunc.Disabled = false;

    LoadDataPageFunc.RemoveProductfromCurrentStore = () => {

        const urllink = `{{ route('store.product.remove') }}/`;
        const datatosend = {
            'store_hash': currenttarget['store_hash'],
            'product_hash': currenttarget['target'],

        };

        SendPostDataURLData(urllink, datatosend, (response) => {
            if (response.success) {
                ModalQuickDismiss('Success', 'Product Removed from Store.');
                Preloaders.ViewStoreinMarket(currenttarget['store_hash'], false, () => {
                    //TODO Fix error here
         
                    gotoPage('ViewStoreMarket', currenttarget['store_hash']);
                });


            }
        });
    };


    LoadDataPageFunc.Settings.Phototype = "ProductMarket";


    Buttons = [
        { icon: '/assets/products.png', label: 'View Product', onclick: "gotoPage('BuyViewProductMarket',currenttarget);return false;" },
        { icon: '/assets/edit.png', label: 'Edit Product', onclick: "gotoPage('EditProductAdmin',currenttarget);return false;" },
        { icon: '/assets/plus-cart.png', label: 'Add to Store', onclick: "gotoPage('AddProducttoStoreAdmin',currenttarget);return false;" },
        { icon: '/assets/minus-cart.png', label: 'Remove from Store', onclick: "gotoPage('RemoveProductfromStoreAdmin',currenttarget);return false;" },
    ];

    LoadDataPageFunc.Main = function () {

        ViewBuilder.build({
            dataurl: '/View/Product/Details/data',
            pageName: 'ManageProductAdmin',
            topbartitle: 'Manage Product',
            defaultback: {
                page: 'BuyViewProductMarket',
                data: currenttarget,
            },
            initialize: (response) => {
                if (typeof response.is_from_store !== 'undefined' && response.is_from_store) {
                    Buttons.push(
                        { icon: '/assets/edit.png', label: 'Edit Product By Store', onclick: "gotoPage('EditProductStoreData',currenttarget);return false;" },
                        // { icon: '/assets/plus-cart.png', label: 'Add to Store', onclick: "gotoPage('AddProducttoCurrentStore',currenttarget);return false;" }, d
                        { icon: '/assets/minus-cart.png', label: 'Remove from Current Store', onclick: "LoadDataPageFunc.RemoveProductfromCurrentStore();return false;" },
                    );


                }
            },
            sections: [
                {
                    phototype: 'ProductMarket',
                    type: 'photos',
                    id: 'PhotosCard',
                    currentdatavar: 'photourl'
                },
                {
                    type: 'details',
                    data: [
                        {
                            h: 3,
                            bold: true,
                            type: 'text',
                            currentdatavar: 'name'
                        },
                        {
                            type: 'text',
                            // currentdatavar: 'price',
                            func: function () {
                                return 'P' + currentData.price + ' / ' + currentData.unitname;
                            },
                        }
                    ]
                    // title: ProductData.name,
                    // description: ProductData.description,
                    // price: ProductData.price,
                    // unit: ProductData.unitname,
                },
                {
                    type: 'buttons',
                    buttons: Buttons
                },
                {
                    type: 'card',
                    id: 'DescriptionCard',
                    hidden: false,
                    currentdatavar: 'description',
                },

            ]
        });


    };






    LoadDataPageFunc.Main();
</script>