'use client';

import { useState } from 'react';
import { PolicySearchContainer } from '@/components/policy-explorer/PolicySearchContainer';
import { PolicyDetailSheet } from '@/components/policy-explorer/PolicyDetailSheet';
import type { PolicySettingSearchResult } from '@/lib/actions/policySettings';

interface PolicyExplorerClientProps {
  initialPolicies: PolicySettingSearchResult[];
}

export function PolicyExplorerClient({
  initialPolicies,
}: PolicyExplorerClientProps) {
  const [selectedPolicy, setSelectedPolicy] = useState<PolicySettingSearchResult | null>(null);
  const [sheetOpen, setSheetOpen] = useState(false);

  const handlePolicyClick = (policy: PolicySettingSearchResult) => {
    setSelectedPolicy(policy);
    setSheetOpen(true);
  };

  return (
    <>
      <PolicySearchContainer
        initialPolicies={initialPolicies}
        onPolicyClick={handlePolicyClick}
      />
      
      <PolicyDetailSheet
        policy={selectedPolicy}
        open={sheetOpen}
        onOpenChange={setSheetOpen}
      />
    </>
  );
}
