<script>
    defaultBackOnclick = null;

    try {
        currentData = @json($current_data);
    } catch (error) {
        currentData = null;
    }

    InitDataPageFuncOBJ();
    LoadDataPageFunc = {};
    LoadDataPageFunc.URLs = {};
    LoadDataPageFunc.URLs.EditUrl = `{{ route('admin.products.addtostore', [], false) }}`;
    LoadDataPageFunc.URLs.CategoryDatalist = `/Products/New/Category/Datalist`;
    LoadDataPageFunc.URLs.SubCategoryDatalist = `/Products/New/SubCategory/Datalist`;
    LoadDataPageFunc.URLs.PhotoUpload = `/File/Upload/Product`;

    LoadDataPageFunc.PageTitle = 'Add Product to Store';

    LoadDataPageFunc.pageName = 'AddProducttoStoreAdmin';

    LoadDataPageFunc.ids = {};
    LoadDataPageFunc.ids.photodropzone = 'EditProductPhotos';

    FormBuilder.build({
        formClass: 'AddProducttoStoreAdmin',
        pageName: LoadDataPageFunc.pageName,
        submitUrl: LoadDataPageFunc.URLs.EditUrl,
        currentDataUrl: '{{ route('admin.products.view.data.addstore', [], false) }}',
        topbartitle: LoadDataPageFunc.PageTitle,
        defaultback: {
            page: 'ManageProductAdmin',
            data: currenttarget,
        },
        onSuccess: (response) => {
            ModalQuickDismissGoto('Success', 'Product Added to Store', ['ManageProductAdmin', 'Go Back',currenttarget]);
            Preloaders.ViewStoreinMarket($('#TargetStore').val());
        },
        onError: (err) => {
            ModalQuickDismiss('Error', 'Failed to Add Product to Store.<br>' + err.message);
        },
        unabletoLoadFunc: function (res) {
            console.log(res);
            ModalQuickDismiss('Error', 'Failed to Add Product to Store.<br>' + err.message);
        },
        onFormGenerated: function () {
            // LoadDataPageFunc.UpdateSubCategoryDatalistasTyped();
            // LoadDataPageFunc.PopulateCategoryDatalist();
        },
        fields: [
            { type: 'select', id: 'TargetStore', label: 'Store Name', currentdatavar: 'store_options', required: true, },
            { type: 'text', id: 'EditProductName', label: 'Name', placeholder: 'Product Name', required: true, currentdatavar: 'name', disabled: true },
            // { type: 'textarea', id: 'EditProductDescription', label: 'Description', required: true, currentdatavar: 'description' },
            // { type: 'text', id: 'EditProductCategory', label: 'Category', placeholder: 'Category', required: true, datalist: 'EditProductCategoryDataList', currentdatavar: 'category' },
            // { type: 'text', id: 'EditProductSubCategory', label: 'Subcategory', placeholder: 'Subcategory', required: true, datalist: 'EditProductSubCategoryDataList', currentdatavar: 'subcategory' },
            { type: 'number', id: 'EditProductPrice', placeholder: '260', label: 'Price (PHP)', required: true, currentdatavar: 'price', disabled: true },
            { type: 'text', id: 'EditProductUnitName', label: 'Unit', placeholder: 'ex 25kg', required: true, currentdatavar: 'unitname', disabled: true },
            // { type: 'number', id: 'EditProductAvailable',placeholder:'ex. 999', label: 'Available Stock', required: true, currentdatavar: 'available' },
            { type: 'text', id: 'EditProductBarcode', label: 'Barcode', placeholder: '12-digit number', maxlength: 12, pattern: '[0-9]*', currentdatavar: 'barcode', disabled: true },
            { type: 'dropzone', id: LoadDataPageFunc.ids.photodropzone, label: 'Photo', uploadUrl: LoadDataPageFunc.URLs.PhotoUpload, currentdatavar: 'photourlDropzone', disabled: true },
            { type: 'button', label: 'Submit', onClick: 'FormBuilder.submit()' },
        ]
    });





</script>