<?php
    /*
        *****************************************************************************
        * MEGA Digital Space - by MEGA Digital Studio                               *
        * ------------------------------------------------------------------------- *
        * CMS Website:  https://megadigital.space                                   *
        * License:  https://megadigital.space/license                               *
        * Owner:  Giorgi Basharuli                                                  *
        * Contact:  online@megadigital.studio                                       *
        * MEGA Digital Studio – Official Development Studio for MEGA Digital Space  *
        * Website:  https://megadigital.studio                                      *
        * ------------------------------------------------------------------------- *
        * Description: This file is a part of the MEGA Digital Space CMS system.    *
        * Unauthorized distribution, modification, or commercial use is strictly -  *
        * prohibited without prior written permission.                              *
        * ------------------------------------------------------------------------- *
        * Copyright (c) 2023-2025 MEGA Digital Studio.                              *
        * All rights reserved.                                                      *
        *****************************************************************************
    */

    require_once($_SERVER["DOCUMENT_ROOT"] . '/engine/data/config.php');
    require_once($_SERVER["DOCUMENT_ROOT"] . "/engine/data/dbconfig.php");

    $widget = [];
    if (!empty($_POST["id"]) && $_POST["action"] == "edit") {
        $widget = $db_connect->get("payment_widgets", "*", ["id" => $_POST["id"]]);
        $widget["translations"] = $db_connect->select("widgets_translations", "*", ["widget_id" => $widget["id"], "widget_type" => "payment_widget"]);

        $widget["settings"] = json_decode($widget["settings"]);
    } else if (!empty($_POST["id"]) && $_POST["action"] == "delete") {
        $db_connect->delete("payment_widgets", ["id" => $_POST["id"]]);

        $db_connect->delete("widgets_translations", ["widget_id" => $_POST["id"], "widget_type" => "payment_widget"]);
    }

    echo json_encode($widget);