import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import classNames from 'classnames';
import { useState } from 'react';
import { ArrowRightIcon } from '../../../../lib/icons/ArrowRight.js';
import { ClimateSettingScheduleCard } from '../../../../lib/seam/components/ClimateSettingScheduleDetails/ClimateSettingScheduleCard.js';
import { withRequiredCommonProps, } from '../../../../lib/seam/components/common-props.js';
import { NestedDeviceDetails } from '../../../../lib/seam/components/DeviceDetails/DeviceDetails.js';
import { useClimateSettingSchedule } from '../../../../lib/seam/thermostats/climate-setting-schedules/use-climate-setting-schedule.js';
import { useUpdateClimateSettingSchedule } from '../../../../lib/seam/thermostats/climate-setting-schedules/use-update-climate-setting-schedule.js';
import { useComponentTelemetry } from '../../../../lib/telemetry/index.js';
import { ContentHeader } from '../../../../lib/ui/layout/ContentHeader.js';
import { DetailRow } from '../../../../lib/ui/layout/DetailRow.js';
import { DetailSection } from '../../../../lib/ui/layout/DetailSection.js';
import { DetailSectionGroup } from '../../../../lib/ui/layout/DetailSectionGroup.js';
import { Snackbar } from '../../../../lib/ui/Snackbar/Snackbar.js';
import { Switch } from '../../../../lib/ui/Switch/Switch.js';
import { ClimateSettingStatus } from '../../../../lib/ui/thermostat/ClimateSettingStatus.js';
import { formatDateTime } from './dates.js';
export const NestedClimateSettingScheduleDetails = withRequiredCommonProps(ClimateSettingScheduleDetails);
export function ClimateSettingScheduleDetails({ climateSettingScheduleId, disableLockUnlock = false, disableDeleteAccessCode = false, onBack, className, errorFilter = () => true, warningFilter = () => true, disableCreateAccessCode, disableEditAccessCode, disableResourceIds = false, disableConnectedAccountInformation = false, disableClimateSettingSchedules, }) {
    useComponentTelemetry('ClimateSettingScheduleDetails');
    const { climateSettingSchedule } = useClimateSettingSchedule(climateSettingScheduleId);
    const { mutate, isSuccess, isError } = useUpdateClimateSettingSchedule();
    const [selectedDeviceId, selectDevice] = useState(null);
    if (climateSettingSchedule == null) {
        return null;
    }
    const isManualOverrideAllowed = climateSettingSchedule.manual_override_allowed ?? false;
    if (selectedDeviceId != null) {
        return (_jsx(NestedDeviceDetails, { deviceId: selectedDeviceId, errorFilter: errorFilter, warningFilter: warningFilter, disableLockUnlock: disableLockUnlock, disableCreateAccessCode: disableCreateAccessCode, disableEditAccessCode: disableEditAccessCode, disableDeleteAccessCode: disableDeleteAccessCode, disableResourceIds: disableResourceIds, disableConnectedAccountInformation: disableConnectedAccountInformation, disableClimateSettingSchedules: disableClimateSettingSchedules, onBack: () => {
                selectDevice(null);
            }, className: className }));
    }
    return (_jsxs(_Fragment, { children: [_jsxs("div", { className: classNames('seam-climate-setting-schedule-details', className), children: [_jsx(ContentHeader, { title: t.climateSettingSchedule, onBack: onBack }), _jsxs("div", { className: 'seam-climate-setting-schedule-details-content', children: [_jsx(ClimateSettingScheduleCard, { climateSettingScheduleId: climateSettingScheduleId, onSelectDevice: selectDevice }), _jsx("div", { className: 'seam-default-setting-message-container', children: _jsxs("span", { className: 'seam-default-setting-message', children: [t.defaultSettingMessagePart1, ' ', _jsx("span", { className: 'seam-default-setting-text', children: t.defaultSetting }), ' ', t.defaultSettingMessagePart2] }) }), _jsxs(DetailSectionGroup, { children: [_jsxs(DetailSection, { children: [_jsx(DetailRow, { label: t.startEndTime, children: _jsxs("span", { className: 'seam-climate-setting-details-value seam-climate-setting-details-schedule-range', children: [formatDateTime(climateSettingSchedule.schedule_starts_at), _jsx(ArrowRightIcon, {}), formatDateTime(climateSettingSchedule.schedule_ends_at)] }) }), _jsx(DetailRow, { label: t.climateSetting, children: _jsx(ClimateSettingStatus, { climateSetting: climateSettingSchedule, iconPlacement: 'right' }) }), _jsx(DetailRow, { label: t.allowManualOverride, children: _jsx("span", { className: 'seam-climate-setting-details-value', children: _jsx(Switch, { checked: isManualOverrideAllowed, onChange: (checked) => {
                                                            mutate({
                                                                climate_setting_schedule_id: climateSettingSchedule.climate_setting_schedule_id,
                                                                manual_override_allowed: checked,
                                                            });
                                                        } }) }) })] }), _jsx(DetailSection, { children: _jsx(DetailRow, { label: t.creationDate, children: _jsx("div", { className: 'seam-creation-date', children: formatDateTime(climateSettingSchedule.created_at) }) }) })] })] })] }), _jsx(Snackbar, { message: t.manualOverrideSuccess, variant: 'success', visible: isSuccess, automaticVisibility: true }), _jsx(Snackbar, { message: t.manualOverrideError, variant: 'error', visible: isError, automaticVisibility: true })] }));
}
const t = {
    climateSettingSchedule: 'Climate setting schedule',
    startEndTime: 'Start/End Time',
    climateSetting: 'Climate setting',
    allowManualOverride: 'Allow manual override',
    creationDate: 'Creation date',
    defaultSettingMessagePart1: 'Thermostat will return to its',
    defaultSetting: 'default setting',
    defaultSettingMessagePart2: 'at end time.',
    manualOverrideSuccess: 'Successfully updated manual override!',
    manualOverrideError: 'Error updating manual override. Please try again.',
};
//# sourceMappingURL=ClimateSettingScheduleDetails.js.map