@{
    ViewData["Title"] = "Real Estate Downloader";
}

<h2>Real Estate Website Downloader</h2>

<form method="post" ng-submit="downloadWebsite()">
    <label for="urlInput">Enter Website URL:</label>
    <input type="text" id="urlInput" ng-model="websiteUrl" placeholder="https://example.com" required />
    <button type="submit">Download</button>
</form>

<div ng-if="downloadStatus">
    <p>{{ downloadStatus }}</p>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<script>
    angular.module('realEstateApp', [])
        .controller('RealEstateController', function ($scope, $http) {
            $scope.websiteUrl = '';
            $scope.downloadStatus = '';

            $scope.downloadWebsite = function () {
                if ($scope.websiteUrl) {
                    $http.post('/api/realestate/download', { url: $scope.websiteUrl })
                        .then(function (response) {
                            $scope.downloadStatus = 'Download successful!';
                            console.log(response.data); // Optional: Handle the downloaded data
                        })
                        .catch(function (error) {
                            $scope.downloadStatus = 'Error downloading website.';
                            console.error(error);
                        });
                }
            };
        });
</script>
